ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-21389 - Cluster and Host Versions Can Change to CURRENT on their Own During an Upgrade (jonathanhurley)
Date Sat, 01 Jul 2017 00:13:37 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-21348 dc9031404 -> a56f3f64c


AMBARI-21389 - Cluster and Host Versions Can Change to CURRENT on their Own During an Upgrade
(jonathanhurley)


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

Branch: refs/heads/branch-feature-AMBARI-21348
Commit: a56f3f64ce7cfc1b33edd456979a428a01a211be
Parents: dc90314
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Fri Jun 30 12:31:48 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Fri Jun 30 20:13:24 2017 -0400

----------------------------------------------------------------------
 .../apache/ambari/annotations/Experimental.java |  6 ++
 .../ambari/annotations/ExperimentalFeature.java |  7 +-
 .../internal/UpgradeResourceProvider.java       | 24 +++++
 .../listeners/upgrade/StackVersionListener.java | 32 +++++--
 .../upgrade/StackVersionListenerTest.java       | 98 +++++++++++---------
 5 files changed, 113 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a56f3f64/ambari-server/src/main/java/org/apache/ambari/annotations/Experimental.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/annotations/Experimental.java b/ambari-server/src/main/java/org/apache/ambari/annotations/Experimental.java
index f51991c..8282095 100644
--- a/ambari-server/src/main/java/org/apache/ambari/annotations/Experimental.java
+++ b/ambari-server/src/main/java/org/apache/ambari/annotations/Experimental.java
@@ -39,4 +39,10 @@ public @interface Experimental {
    * @return
    */
   ExperimentalFeature feature();
+
+  /**
+   * Any notes to why the annotation is used or any other action that may be
+   * useful.
+   */
+  String comment() default "";
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a56f3f64/ambari-server/src/main/java/org/apache/ambari/annotations/ExperimentalFeature.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/annotations/ExperimentalFeature.java
b/ambari-server/src/main/java/org/apache/ambari/annotations/ExperimentalFeature.java
index 1d5ba0e..2bd1252 100644
--- a/ambari-server/src/main/java/org/apache/ambari/annotations/ExperimentalFeature.java
+++ b/ambari-server/src/main/java/org/apache/ambari/annotations/ExperimentalFeature.java
@@ -40,5 +40,10 @@ public enum ExperimentalFeature {
   /**
    * Used for code that is targeted for patch upgrades
    */
-  PATCH_UPGRADES
+  PATCH_UPGRADES,
+
+  /**
+   * Upgrades from one stack vendor (FOO-1.0) to another (BAR-5.5.0).
+   */
+  STACK_UPGRADES_BETWEEN_VENDORS
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a56f3f64/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 822f94d..25e8cab 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -17,6 +17,9 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_PACKAGE_FOLDER;
+
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -92,6 +95,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.UpgradeContext;
 import org.apache.ambari.server.state.UpgradeContextFactory;
 import org.apache.ambari.server.state.UpgradeHelper;
@@ -1308,6 +1312,26 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     // Apply additional parameters to the command that come from the stage.
     applyAdditionalParameters(wrapper, params);
 
+    // the ru_execute_tasks invokes scripts - it needs information about where
+    // the scripts live and for that it should always use the target repository
+    // stack
+    if (CollectionUtils.isNotEmpty(wrapper.getTasks())
+        && wrapper.getTasks().get(0).getService() != null) {
+
+      AmbariMetaInfo ambariMetaInfo = s_metaProvider.get();
+      StackId stackId = context.getTargetStackId();
+
+      StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(),
+          stackId.getStackVersion());
+
+      String serviceName = wrapper.getTasks().get(0).getService();
+      ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
+          stackId.getStackVersion(), serviceName);
+
+      params.put(SERVICE_PACKAGE_FOLDER, serviceInfo.getServicePackageFolder());
+      params.put(HOOKS_FOLDER, stackInfo.getStackHooksFolder());
+    }
+
     ActionExecutionContext actionContext = new ActionExecutionContext(cluster.getClusterName(),
         "ru_execute_tasks", Collections.singletonList(filter), params);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a56f3f64/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
index 4600912..3af5520 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
@@ -17,6 +17,9 @@
  */
 package org.apache.ambari.server.events.listeners.upgrade;
 
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.EagerSingleton;
 import org.apache.ambari.server.events.HostComponentVersionAdvertisedEvent;
@@ -53,6 +56,12 @@ public class StackVersionListener {
   private final static Logger LOG = LoggerFactory.getLogger(StackVersionListener.class);
   public static final String UNKNOWN_VERSION = State.UNKNOWN.toString();
 
+  /**
+   * Used to prevent multiple threads from trying to update the same host
+   * version simultaneously.
+   */
+  private Lock m_stackVersionLock = new ReentrantLock();
+
   @Inject
   private RepositoryVersionDAO repositoryVersionDAO;
 
@@ -95,6 +104,8 @@ public class StackVersionListener {
       }
     }
 
+    m_stackVersionLock.lock();
+
     // Update host component version value if needed
     try {
       ServiceComponent sc = cluster.getService(sch.getServiceName()).getServiceComponent(
@@ -126,6 +137,8 @@ public class StackVersionListener {
       LOG.error(
           "Unable to propagate version for ServiceHostComponent on component: {}, host: {}.
Error: {}",
           sch.getServiceComponentName(), sch.getHostName(), e.getMessage());
+    } finally {
+      m_stackVersionLock.unlock();
     }
   }
 
@@ -158,8 +171,9 @@ public class StackVersionListener {
     // was this version expected
     boolean newVersionMatchesDesired = StringUtils.equals(desiredVersion, newVersion);
 
-    // was the prior version UNKNOWN
-    boolean previousVersionIsUnknown = StringUtils.equalsIgnoreCase(UNKNOWN_VERSION, previousVersion);
+    // was the prior version UNKNOWN or null
+    boolean previousVersionIsUnknown = StringUtils.equalsIgnoreCase(UNKNOWN_VERSION,
+        previousVersion) || StringUtils.isBlank(previousVersion);
 
     boolean desiredVersionIsUnknown = StringUtils.equalsIgnoreCase(UNKNOWN_VERSION, desiredVersion);
 
@@ -193,16 +207,16 @@ public class StackVersionListener {
       if (newVersionMatchesDesired) {
         if (isUpgradeInProgressForThisComponent) {
           sch.setStackVersion(cluster.getDesiredStackVersion());
-          setUpgradeStateAndRecalculateHostVersions(cluster, sch, UpgradeState.COMPLETE);
+          setUpgradeStateIfChanged(cluster, sch, UpgradeState.COMPLETE);
         } else {
           // no upgrade in progress for this component, then this should always
           // be NONE
-          setUpgradeStateAndRecalculateHostVersions(cluster, sch, UpgradeState.NONE);
+          setUpgradeStateIfChanged(cluster, sch, UpgradeState.NONE);
         }
       } else {
         // if the versions don't match for any reason, regardless of upgrade
         // state, then VERSION_MISMATCH it
-        setUpgradeStateAndRecalculateHostVersions(cluster, sch, UpgradeState.VERSION_MISMATCH);
+        setUpgradeStateIfChanged(cluster, sch, UpgradeState.VERSION_MISMATCH);
       }
     }
   }
@@ -226,11 +240,15 @@ public class StackVersionListener {
   }
 
   /**
+   * Sets the upgrade state on the component if it has changed. This method will
+   * not trigger an sort of {@link ClusterVersionEntity} or
+   * {@link HostVersionEntity} recalculation.
+   *
    * @param sch
    * @param upgradeState
    * @throws AmbariException
    */
-  private void setUpgradeStateAndRecalculateHostVersions(Cluster cluster, ServiceComponentHost
sch,
+  private void setUpgradeStateIfChanged(Cluster cluster, ServiceComponentHost sch,
       UpgradeState upgradeState) throws AmbariException {
 
     // don't need to recalculate anything here if the upgrade state is not changing
@@ -240,8 +258,6 @@ public class StackVersionListener {
 
     // if the upgrade state changes, then also recalculate host versions
     sch.setUpgradeState(upgradeState);
-
-    recalculateHostVersionAndClusterVersion(cluster, sch);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a56f3f64/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
index 7b8b68a..f20c46c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
@@ -17,12 +17,13 @@
  */
 package org.apache.ambari.server.events.listeners.upgrade;
 
-import static org.easymock.EasyMock.anyString;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 
 import java.lang.reflect.Field;
 
+import org.apache.ambari.annotations.Experimental;
+import org.apache.ambari.annotations.ExperimentalFeature;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.events.HostComponentVersionAdvertisedEvent;
@@ -31,12 +32,12 @@ import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.ComponentInfo;
 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.apache.ambari.server.state.UpgradeState;
+import org.easymock.EasyMock;
 import org.easymock.EasyMockRunner;
 import org.easymock.EasyMockSupport;
 import org.easymock.Mock;
@@ -72,8 +73,6 @@ public class StackVersionListenerTest extends EasyMockSupport {
   private Service service;
   private ServiceComponent serviceComponent;
   private VersionEventPublisher publisher = new VersionEventPublisher();
-  private AmbariMetaInfo ambariMetaInfo;
-  private ComponentInfo componentInfo;
   private StackId stackId;
 
   @TestSubject
@@ -88,18 +87,12 @@ public class StackVersionListenerTest extends EasyMockSupport {
     sch = createNiceMock(ServiceComponentHost.class);
     service = createNiceMock(Service.class);
     serviceComponent = createNiceMock(ServiceComponent.class);
-    componentInfo = createNiceMock(ComponentInfo.class);
     stackId = createNiceMock(StackId.class);
 
-    ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
-
-    expect(ambariMetaInfoProvider.get()).andReturn(ambariMetaInfo);
-    expect(ambariMetaInfo.getComponent(anyString(),anyString(),anyString(),anyString())).andReturn(componentInfo);
-
-    expect(cluster.getDesiredStackVersion()).andReturn(stackId).atLeastOnce();
-    expect(stackId.getStackName()).andReturn(STACK_NAME);
-    expect(stackId.getStackVersion()).andReturn(STACK_VERSION);
-    expect(cluster.getClusterId()).andReturn(CLUSTER_ID);
+    expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes();
+    expect(stackId.getStackName()).andReturn(STACK_NAME).anyTimes();
+    expect(stackId.getStackVersion()).andReturn(STACK_VERSION).anyTimes();
+    expect(cluster.getClusterId()).andReturn(CLUSTER_ID).atLeastOnce();
 
     expect(cluster.getService(SERVICE_NAME)).andReturn(service).atLeastOnce();
     expect(service.getServiceComponent(SERVICE_COMPONENT_NAME)).andReturn(serviceComponent).atLeastOnce();
@@ -109,8 +102,9 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateHostVersionStateWhenVersionIsNullAndNewVersionIsNotBlank() throws
AmbariException {
-    expect(sch.getVersion()).andReturn(null);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(null).atLeastOnce();
+    expect(serviceComponent.getDesiredVersion()).andReturn(INVALID_NEW_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setVersion(INVALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(null).once();
@@ -122,8 +116,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateHostVersionStateWhenVersionIsUnknownAndNewVersionIsNotBlank()
throws AmbariException {
-    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setVersion(INVALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(null).once();
@@ -135,8 +129,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateClusterVersionStateWhenVersionIsNullAndNewVersionIsValid() throws
AmbariException {
-    expect(sch.getVersion()).andReturn(null);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(null).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once();
@@ -150,8 +144,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateClusterVersionStateWhenVersionIsUnknownAndNewVersionIsValid()
throws AmbariException {
-    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once();
@@ -165,8 +159,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateHostVersionStateWhenComponentDesiredVersionIsUnknownAndNewVersionIsNotValid()
throws AmbariException {
-    expect(serviceComponent.getDesiredVersion()).andReturn(UNKNOWN_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(serviceComponent.getDesiredVersion()).andReturn(UNKNOWN_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     serviceComponent.setDesiredVersion(INVALID_NEW_VERSION);
     expectLastCall().once();
     sch.setUpgradeState(UpgradeState.NONE);
@@ -182,8 +176,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateClusterVersionStateWhenComponentDesiredVersionIsUnknownAndNewVersionIsValid()
throws AmbariException {
-    expect(serviceComponent.getDesiredVersion()).andReturn(UNKNOWN_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(serviceComponent.getDesiredVersion()).andReturn(UNKNOWN_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     serviceComponent.setDesiredVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     sch.setUpgradeState(UpgradeState.NONE);
@@ -201,7 +195,7 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testRecalculateClusterVersionStateWhenVersionNotAdvertised() throws AmbariException
{
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.FALSE);
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.FALSE).atLeastOnce();
     replayAll();
     sendEventAndVerify(VALID_NEW_VERSION);
   }
@@ -218,9 +212,10 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testSetUpgradeStateToCompleteWhenUpgradeIsInProgressAndNewVersionIsEqualToComponentDesiredVersion()
{
-    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION);
-    expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(cluster.getUpgradeInProgress()).andReturn(EasyMock.niceMock(UpgradeEntity.class)).atLeastOnce();
+    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setUpgradeState(UpgradeState.COMPLETE);
     expectLastCall().once();
 
@@ -232,9 +227,10 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testSetUpgradeStateToVersionMismatchWhenUpgradeIsInProgressAndNewVersionIsNotEqualToComponentDesiredVersion()
{
-    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION);
-    expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(cluster.getUpgradeInProgress()).andReturn(createNiceMock(UpgradeEntity.class)).atLeastOnce();
+    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setUpgradeState(UpgradeState.VERSION_MISMATCH);
     expectLastCall().once();
 
@@ -246,11 +242,11 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testSetUpgradeStateToCompleteWhenHostHasVersionMismatchAndNewVersionIsEqualToComponentDesiredVersionAndClusterUpgradeIsInProgress()
{
-    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION);
-    expect(sch.getUpgradeState()).andReturn(UpgradeState.VERSION_MISMATCH);
-    expect(cluster.getUpgradeInProgress()).andReturn(DUMMY_UPGRADE_ENTITY);
+    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(sch.getUpgradeState()).andReturn(UpgradeState.VERSION_MISMATCH).atLeastOnce();
+    expect(cluster.getUpgradeInProgress()).andReturn(DUMMY_UPGRADE_ENTITY).atLeastOnce();
     expect(serviceComponent.getDesiredVersion()).andStubReturn(VALID_NEW_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setUpgradeState(UpgradeState.COMPLETE);
     expectLastCall().once();
 
@@ -261,10 +257,10 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testSetUpgradeStateToNoneWhenHostHasVersionMismatchAndNewVersionIsEqualToComponentDesiredVersion()
{
-    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION);
-    expect(sch.getUpgradeState()).andReturn(UpgradeState.VERSION_MISMATCH);
+    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(sch.getUpgradeState()).andReturn(UpgradeState.VERSION_MISMATCH).atLeastOnce();
     expect(serviceComponent.getDesiredVersion()).andStubReturn(VALID_NEW_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
     sch.setUpgradeState(UpgradeState.NONE);
     expectLastCall().once();
 
@@ -274,9 +270,20 @@ public class StackVersionListenerTest extends EasyMockSupport {
   }
 
   @Test
+  @Experimental(
+      feature = ExperimentalFeature.STACK_UPGRADES_BETWEEN_VENDORS,
+      comment = "Version Mismatch happened previously when not in an upgrade")
   public void testSetUpgradeStateToVersionMismatchByDefaultWhenHostAndNewVersionsAreValid()
{
-    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(serviceComponent.getDesiredVersion()).andReturn(VALID_PREVIOUS_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
+
+    // !!! VERSION_MISMATCH might need to be allowed to happen when not in an
+    // upgrade
+    expect(cluster.getUpgradeInProgress()).andReturn(
+        EasyMock.niceMock(UpgradeEntity.class)).atLeastOnce();
+    expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS).atLeastOnce();
+
     sch.setUpgradeState(UpgradeState.VERSION_MISMATCH);
     expectLastCall().once();
 
@@ -287,8 +294,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
 
   @Test
   public void testSetRepositoryVersion() throws Exception {
-    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION);
-    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
+    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION).atLeastOnce();
+    expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE).atLeastOnce();
 
     RepositoryVersionDAO dao = createNiceMock(RepositoryVersionDAO.class);
     RepositoryVersionEntity entity = createNiceMock(RepositoryVersionEntity.class);
@@ -321,7 +328,8 @@ public class StackVersionListenerTest extends EasyMockSupport {
   @Test
   public void testRepositoryVersionNotSetDuringUpgrade() throws Exception {
     // this call will make it seem like there is an upgrade in progress
-    expect(cluster.getUpgradeInProgress()).andReturn(createNiceMock(UpgradeEntity.class));
+    expect(cluster.getUpgradeInProgress()).andReturn(
+        createNiceMock(UpgradeEntity.class)).atLeastOnce();
 
     // create the DAO - nothing will be called on it, so make it strict
     RepositoryVersionDAO dao = createStrictMock(RepositoryVersionDAO.class);


Mime
View raw message