Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 bf86017d8 -> 07a3f950a


AMBARI-18416. Optimize stack manager initialization for Ambari Server Unit 
Tests (aonishuk)


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

Branch: refs/heads/branch-2.5
Commit: 07a3f950a510cc431ace458bde063d88175a4f94
Parents: bf86017
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Mon Sep 19 19:13:44 2016 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Mon Sep 19 19:13:44 2016 +0300

----------------------------------------------------------------------
 .../ambari/server/stack/StackManager.java       |  17 +-
 .../server/api/services/AmbariMetaInfoTest.java |  41 +++--
 .../AmbariManagementControllerTest.java         |   4 +
 ...ClusterStackVersionResourceProviderTest.java |   1 +
 .../server/orm/InMemoryDefaultTestModule.java   |  14 +-
 .../ambari/server/stack/StackManagerMock.java   | 166 +++++++++++++++++++
 .../ambari/server/state/UpgradeHelperTest.java  |  26 +++
 7 files changed, 251 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java 
b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
index 6c0d5e4..0e2e0d8 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
@@ -99,7 +99,10 @@ public class StackManager {
   /**
    * Map of stack id to stack info
    */
-  private Map<String, StackInfo> stackMap = new HashMap<String, StackInfo>();
+  protected Map<String, StackInfo> stackMap = new HashMap<String, StackInfo>();
+  protected Map<String, ServiceModule> commonServiceModules;
+  protected Map<String, StackModule> stackModules;
+  protected Map<String, ExtensionModule> extensionModules;
 
   /**
    * Map of extension id to extension info
@@ -152,11 +155,7 @@ public class StackManager {
     stackContext = new StackContext(metaInfoDAO, actionMetadata, osFamily);
     extensionMap = new HashMap<String, ExtensionInfo>();
 
-    Map<String, ServiceModule> commonServiceModules = 
parseCommonServicesDirectory(commonServicesRoot);
-    Map<String, StackModule> stackModules = parseStackDirectory(stackRoot);
-    LOG.info("About to parse extension directories");
-    Map<String, ExtensionModule> extensionModules = null;
-    extensionModules = parseExtensionDirectory(extensionRoot);
+    parseDirectories(stackRoot, commonServicesRoot, extensionRoot);
 
     //Read the extension links from the DB
     for (StackModule module : stackModules.values()) {
@@ -183,6 +182,12 @@ public class StackManager {
     populateDB(stackDao, extensionDao);
   }
 
+  protected void parseDirectories(File stackRoot, File commonServicesRoot, 
File extensionRoot) throws AmbariException {
+    commonServiceModules = parseCommonServicesDirectory(commonServicesRoot);
+    stackModules = parseStackDirectory(stackRoot);
+    LOG.info("About to parse extension directories");
+    extensionModules = parseExtensionDirectory(extensionRoot);
+  }
   private void populateDB(StackDAO stackDao, ExtensionDAO extensionDao) throws 
AmbariException {
     // for every stack read in, ensure that we have a database entry for it;
     // don't put try/catch logic around this since a failure here will

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 0f8ed9c..592403d 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -248,7 +248,7 @@ public class AmbariMetaInfoTest {
     // Scenario: user has no internet and does nothing to repos via api
     // use the default
     String buildDir = tmpFolder.getRoot().getAbsolutePath();
-    AmbariMetaInfo ambariMetaInfo = setupTempAmbariMetaInfo(buildDir);
+    setupTempAmbariMetaInfoDirs(buildDir);
     // The current stack already has (HDP, 2.1.1, redhat6).
 
     // Deleting the json file referenced by the latestBaseUrl to simulate No
@@ -261,7 +261,7 @@ public class AmbariMetaInfoTest {
       FileUtils.deleteQuietly(latestUrlFile);
       assertTrue(!latestUrlFile.exists());
     }
-    ambariMetaInfo.init();
+    AmbariMetaInfo ambariMetaInfo = 
setupTempAmbariMetaInfoExistingDirs(buildDir);
 
     List<RepositoryInfo> redhat6Repo = ambariMetaInfo.getRepositories(
         STACK_NAME_HDP, "2.1.1", "redhat6");
@@ -583,9 +583,9 @@ public class AmbariMetaInfoTest {
       stackRoot = new 
File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
       version = new File(new 
File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), 
"version");
     }
-    File stackRootTmp = new File(buildDir + "/ambari-metaInfo"); 
stackRootTmp.mkdir();
+    File stackRootTmp = getStackRootTmp(buildDir);
+    stackRootTmp.mkdir();
     FileUtils.copyDirectory(stackRoot, stackRootTmp);
-    AmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, 
version);
     //todo
     //ambariMetaInfo.injector = injector;
     File f1, f2, f3;
@@ -596,7 +596,7 @@ public class AmbariMetaInfoTest {
       f3.createNewFile();
     }
 
-    ambariMetaInfo.init();
+    AmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, 
version);
 
     // Tests the stack is loaded as expected
     getServices();
@@ -1984,21 +1984,42 @@ public class AmbariMetaInfoTest {
     Assert.assertNotNull(descriptor.getService("HDFS"));
   }
 
+  private File getStackRootTmp(String buildDir) {
+    return new File(buildDir + "/ambari-metaInfo");
+  }
 
-  private TestAmbariMetaInfo setupTempAmbariMetaInfo(String buildDir) throws 
Exception {
-    File stackRootTmp = new File(buildDir + "/ambari-metaInfo");
-    File stackRoot = new File("src/test/resources/stacks");
+  private File getVersion() {
     File version = new File("src/test/resources/version");
 
     if (System.getProperty("os.name").contains("Windows")) {
-      stackRoot = new 
File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
       version = new File(new 
File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), 
"version");
     }
 
+    return version;
+  }
+
+  private void setupTempAmbariMetaInfoDirs(String buildDir) throws Exception {
+    File stackRootTmp = getStackRootTmp(buildDir);
+    File stackRoot = new File("src/test/resources/stacks");
+
+    if (System.getProperty("os.name").contains("Windows")) {
+      stackRoot = new 
File(ClassLoader.getSystemClassLoader().getResource("stacks").getPath());
+    }
+
     stackRootTmp.mkdir();
     FileUtils.copyDirectory(stackRoot, stackRootTmp);
-    TestAmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, 
version);
+  }
+
+  private TestAmbariMetaInfo setupTempAmbariMetaInfo(String buildDir) throws 
Exception {
+    setupTempAmbariMetaInfoDirs(buildDir);
+    TestAmbariMetaInfo ambariMetaInfo = 
setupTempAmbariMetaInfoExistingDirs(buildDir);
+    return ambariMetaInfo;
+  }
 
+  private TestAmbariMetaInfo setupTempAmbariMetaInfoExistingDirs(String 
buildDir) throws Exception {
+    File version = getVersion();
+    File stackRootTmp = getStackRootTmp(buildDir);
+    TestAmbariMetaInfo ambariMetaInfo = createAmbariMetaInfo(stackRootTmp, 
version);
     return ambariMetaInfo;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 40a11fe..a8a16ab 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -116,6 +116,7 @@ import 
org.apache.ambari.server.orm.entities.WidgetLayoutUserWidgetEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.serveraction.ServerAction;
+import org.apache.ambari.server.stack.StackManagerMock;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -232,6 +233,7 @@ public class AmbariManagementControllerTest {
   private HostDAO hostDAO;
   private TopologyHostInfoDAO topologyHostInfoDAO;
   private HostRoleCommandDAO hostRoleCommandDAO;
+  private StackManagerMock stackManagerMock;
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -272,6 +274,7 @@ public class AmbariManagementControllerTest {
     hostDAO = injector.getInstance(HostDAO.class);
     topologyHostInfoDAO = injector.getInstance(TopologyHostInfoDAO.class);
     hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+    stackManagerMock = (StackManagerMock) ambariMetaInfo.getStackManager();
     EasyMock.replay(injector.getInstance(AuditLogger.class));
   }
 
@@ -8652,6 +8655,7 @@ public class AmbariManagementControllerTest {
       assertTrue(INCORRECT_BASE_URL.equals(repositoryInfo.getBaseUrl()));
     }
 
+    stackManagerMock.invalidateCurrentPaths();
     controller.updateStacks();
 
     stackInfo = ambariMetaInfo.getStack(STACK_NAME, STACK_VERSION);

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index a521139..ebd42a2 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -1018,6 +1018,7 @@ public class ClusterStackVersionResourceProviderTest {
 
     TopologyManager topologyManager = 
injector.getInstance(TopologyManager.class);
     StageUtils.setTopologyManager(topologyManager);
+    StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
     
expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(Collections.<ClusterVersionEntity>emptyList()).once();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
index e327a04..7f5842f 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
@@ -23,10 +23,14 @@ import java.util.Collections;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
-
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.util.Modules;
 import org.apache.ambari.server.audit.AuditLogger;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.stack.StackManager;
+import org.apache.ambari.server.stack.StackManagerFactory;
+import org.apache.ambari.server.stack.StackManagerMock;
 import org.easymock.EasyMock;
 import org.springframework.beans.factory.config.BeanDefinition;
 
@@ -92,7 +96,13 @@ public class InMemoryDefaultTestModule extends 
AbstractModule {
     }
 
     try {
-      install(new BeanDefinitionsCachingTestControllerModule(properties));
+      install(Modules.override(new 
BeanDefinitionsCachingTestControllerModule(properties)).with(new 
AbstractModule() {
+        @Override
+        protected void configure() {
+          // Cache parsed stacks.
+          install(new FactoryModuleBuilder().implement(StackManager.class, 
StackManagerMock.class).build(StackManagerFactory.class));
+        }
+      }));
       AuditLogger al = EasyMock.createNiceMock(AuditLogger.class);
       EasyMock.expect(al.isEnabled()).andReturn(false).anyTimes();
       bind(AuditLogger.class).toInstance(al);

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
new file mode 100644
index 0000000..1b9e15f
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/stack/StackManagerMock.java
@@ -0,0 +1,166 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.stack;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.annotation.Nullable;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.metadata.ActionMetadata;
+import org.apache.ambari.server.orm.dao.ExtensionDAO;
+import org.apache.ambari.server.orm.dao.ExtensionLinkDAO;
+import org.apache.ambari.server.orm.dao.MetainfoDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.state.stack.OsFamily;
+
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+
+/**
+ * Directory tree rescans and stack modules parsing take much time on every 
module init.
+ * This class enhances {@code}StackManager{@code} to reuse already parsed 
modules.
+ */
+public class StackManagerMock extends StackManager {
+
+  // Ensure correct behavior during the parallel test execution.
+  private static final Lock lock = new ReentrantLock();
+
+  // Some tests use different stack locations.
+  private static final Map<ModulesPathsKey, CachedModules> 
pathsToCachedModulesMap = new HashMap<>();
+
+  public static void invalidateKey(File stackRoot, File commonServicesRoot, 
File extensionRoot) {
+    ModulesPathsKey pathsKey = new ModulesPathsKey(stackRoot, 
commonServicesRoot, extensionRoot);
+    pathsToCachedModulesMap.remove(pathsKey);
+  }
+
+  // Paths for this instance.
+  private File currentStackRoot;
+  private File currentCommonServicesRoot;
+  private File currentExtensionRoot;
+
+  public void invalidateCurrentPaths() {
+    invalidateKey(currentStackRoot, currentCommonServicesRoot, 
currentExtensionRoot);
+  }
+
+  private static class ModulesPathsKey {
+    private String stackRoot;
+    private String commonServicesRoot;
+    private String extensionRoot;
+
+    public ModulesPathsKey(File stackRoot, File commonServicesRoot, File 
extensionRoot) {
+      this.stackRoot = stackRoot == null ? "" : stackRoot.getPath();
+      this.commonServicesRoot = commonServicesRoot == null ? "" : 
commonServicesRoot.getPath();
+      this.extensionRoot = extensionRoot == null ? "" : 
extensionRoot.getPath();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      ModulesPathsKey that = (ModulesPathsKey) o;
+
+      if (stackRoot != null ? !stackRoot.equals(that.stackRoot) : 
that.stackRoot != null) return false;
+      if (commonServicesRoot != null ? 
!commonServicesRoot.equals(that.commonServicesRoot) : that.commonServicesRoot 
!= null)
+        return false;
+      return !(extensionRoot != null ? 
!extensionRoot.equals(that.extensionRoot) : that.extensionRoot != null);
+
+    }
+
+    @Override
+    public int hashCode() {
+      int result = stackRoot != null ? stackRoot.hashCode() : 0;
+      result = 31 * result + (commonServicesRoot != null ? 
commonServicesRoot.hashCode() : 0);
+      result = 31 * result + (extensionRoot != null ? extensionRoot.hashCode() 
: 0);
+      return result;
+    }
+  }
+
+  private static class CachedModules {
+    private Map<String, ServiceModule> cachedCommonServiceModules;
+    private Map<String, StackModule> cachedStackModules;
+    private Map<String, ExtensionModule> cachedExtensionModules;
+    private Map<String, StackInfo> cachedStackMap;
+
+    public CachedModules(Map<String, ServiceModule> 
cachedCommonServiceModules, Map<String, StackModule> cachedStackModules,
+                         Map<String, ExtensionModule> cachedExtensionModules, 
Map<String, StackInfo> cachedStackMap) {
+      this.cachedCommonServiceModules = cachedCommonServiceModules;
+      this.cachedStackModules = cachedStackModules;
+      this.cachedExtensionModules = cachedExtensionModules;
+      this.cachedStackMap = cachedStackMap;
+    }
+
+    public Map<String, ServiceModule> getCachedCommonServiceModules() {
+      return cachedCommonServiceModules;
+    }
+
+    public Map<String, StackModule> getCachedStackModules() {
+      return cachedStackModules;
+    }
+
+    public Map<String, ExtensionModule> getCachedExtensionModules() {
+      return cachedExtensionModules;
+    }
+
+    public Map<String, StackInfo> getCachedStackMap() {
+      return cachedStackMap;
+    }
+  }
+
+  @Inject
+  public StackManagerMock(@Assisted("stackRoot") File stackRoot, @Nullable 
@Assisted("commonServicesRoot")
+      File commonServicesRoot, @Assisted("extensionRoot") @Nullable File 
extensionRoot,
+                          @Assisted OsFamily osFamily, @Assisted boolean 
validate, MetainfoDAO metaInfoDAO,
+                          ActionMetadata actionMetadata, StackDAO stackDao, 
ExtensionDAO extensionDao,
+                          ExtensionLinkDAO linkDao) throws AmbariException {
+    super(stackRoot, commonServicesRoot, extensionRoot, osFamily, validate, 
metaInfoDAO, actionMetadata, stackDao, extensionDao, linkDao);
+    currentStackRoot = stackRoot;
+    currentCommonServicesRoot = commonServicesRoot;
+    currentExtensionRoot = extensionRoot;
+  }
+
+  @Override
+  protected void parseDirectories(File stackRoot, File commonServicesRoot, 
File extensionRoot) throws AmbariException {
+    try {
+      // Ensure correct behavior during the parallel test execution.
+      lock.lock();
+
+      ModulesPathsKey pathsKey = new ModulesPathsKey(stackRoot, 
commonServicesRoot, extensionRoot);
+      CachedModules cachedModules = pathsToCachedModulesMap.get(pathsKey);
+
+      if (cachedModules == null) {
+        super.parseDirectories(stackRoot, commonServicesRoot, extensionRoot);
+        CachedModules newEntry = new CachedModules(commonServiceModules, 
stackModules, extensionModules, stackMap);
+        pathsToCachedModulesMap.put(pathsKey, newEntry);
+      } else {
+        commonServiceModules = cachedModules.getCachedCommonServiceModules();
+        stackModules = cachedModules.getCachedStackModules();
+        extensionModules = cachedModules.getCachedExtensionModules();
+        stackMap = cachedModules.getCachedStackMap();
+      }
+    } finally {
+      lock.unlock();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/07a3f950/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index 34bac2a..c2e1f75 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -48,6 +48,7 @@ import 
org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.stack.HostsType;
 import org.apache.ambari.server.stack.MasterHostResolver;
+import org.apache.ambari.server.stack.StackManagerMock;
 import org.apache.ambari.server.state.UpgradeHelper.UpgradeGroupHolder;
 import org.apache.ambari.server.state.stack.ConfigUpgradePack;
 import org.apache.ambari.server.state.stack.UpgradePack;
@@ -92,6 +93,7 @@ public class UpgradeHelperTest {
 
   private Injector injector;
   private AmbariMetaInfo ambariMetaInfo;
+  private StackManagerMock stackManagerMock;
   private OrmTestHelper helper;
   private MasterHostResolver m_masterHostResolver;
   private UpgradeHelper m_upgradeHelper;
@@ -134,6 +136,7 @@ public class UpgradeHelperTest {
 
     helper = injector.getInstance(OrmTestHelper.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+    stackManagerMock = (StackManagerMock) ambariMetaInfo.getStackManager();
     m_upgradeHelper = injector.getInstance(UpgradeHelper.class);
     m_masterHostResolver = EasyMock.createMock(MasterHostResolver.class);
     m_managementController = 
injector.getInstance(AmbariManagementController.class);
@@ -242,6 +245,10 @@ public class UpgradeHelperTest {
     assertEquals(6, groups.get(1).items.size());
     assertEquals(9, groups.get(2).items.size());
     assertEquals(8, groups.get(3).items.size());
+
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
   @Test
@@ -295,6 +302,10 @@ public class UpgradeHelperTest {
     assertEquals(3, groups.get(0).items.size());
     assertEquals(7, groups.get(1).items.size());
     assertEquals(2, groups.get(2).items.size());
+
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
   @Test
@@ -349,6 +360,10 @@ public class UpgradeHelperTest {
     assertEquals(3, groups.get(0).items.size());
     assertEquals(6, groups.get(1).items.size());
     assertEquals(1, groups.get(2).items.size());
+
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
   @Test
@@ -383,6 +398,9 @@ public class UpgradeHelperTest {
     assertEquals("Calculating Properties", stageWrappers.get(4).getText());
     assertEquals("Calculating HDFS Properties", 
stageWrappers.get(5).getText());
 
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
   /**
@@ -427,6 +445,10 @@ public class UpgradeHelperTest {
         assertFalse(hosts.contains(hostInMaintenanceMode.getHostName()));
       }
     }
+
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
   /**
@@ -1156,6 +1178,10 @@ public class UpgradeHelperTest {
     assertEquals(5, groups.get(1).items.size());
     assertEquals(9, groups.get(2).items.size());
     assertEquals(8, groups.get(3).items.size());
+
+    // Do stacks cleanup
+    stackManagerMock.invalidateCurrentPaths();
+    ambariMetaInfo.init();
   }
 
 

Reply via email to