Repository: ambari Updated Branches: refs/heads/branch-feature-AMBARI-12556 aaa821cc2 -> a2632675a
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2632675/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java index 576f308..e2d9cc6 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java @@ -973,7 +973,7 @@ public class UpgradeResourceProviderTest { requestProps.clear(); // Now perform a downgrade requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); - requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2"); + requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.0"); requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_direction"); requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true"); requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.3"); @@ -992,8 +992,9 @@ public class UpgradeResourceProviderTest { } } assertNotNull(upgrade); - assertEquals("Downgrade groups reduced from 3 to 2", 2, upgrade.getUpgradeGroups().size()); - group = upgrade.getUpgradeGroups().get(1); + List<UpgradeGroupEntity> groups = upgrade.getUpgradeGroups(); + assertEquals("Downgrade groups reduced from 3 to 2", 1, groups.size()); + group = upgrade.getUpgradeGroups().get(0); assertEquals("Execution items increased from 1 to 2", 2, group.getItems().size()); } @@ -1060,7 +1061,7 @@ public class UpgradeResourceProviderTest { assertEquals(oldStack, sc.getDesiredStackId()); for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) { - assertEquals(oldStack.getStackVersion(), sch.getVersion()); + assertEquals(repoVersionEntity2110.getVersion(), sch.getVersion()); } } } @@ -1100,14 +1101,10 @@ public class UpgradeResourceProviderTest { assertFalse(oldStack.equals(newStack)); for (Service s : cluster.getServices().values()) { - assertEquals(newStack, s.getDesiredStackId()); + assertEquals(repoVersionEntity2200, s.getDesiredRepositoryVersion()); for (ServiceComponent sc : s.getServiceComponents().values()) { - assertEquals(newStack, sc.getDesiredStackId()); - - for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) { - assertEquals(newStack.getStackVersion(), sch.getVersion()); - } + assertEquals(repoVersionEntity2200, sc.getDesiredRepositoryVersion()); } } } @@ -1568,7 +1565,7 @@ public class UpgradeResourceProviderTest { component = service.getServiceComponent("DRPC_SERVER"); assertNotNull(component); - assertEquals("UNKNOWN", component.getDesiredVersion()); + assertEquals(repoVersionEntity2110, component.getDesiredRepositoryVersion()); hostComponent = component.getServiceComponentHost("h1"); assertEquals(UpgradeState.NONE, hostComponent.getUpgradeState()); http://git-wip-us.apache.org/repos/asf/ambari/blob/a2632675/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 a74a1d2..e2e68fc 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,7 +17,6 @@ */ 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; @@ -28,6 +27,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.events.HostComponentVersionAdvertisedEvent; import org.apache.ambari.server.events.publishers.VersionEventPublisher; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; +import org.apache.ambari.server.orm.entities.HostVersionEntity; import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; import org.apache.ambari.server.orm.entities.UpgradeEntity; import org.apache.ambari.server.state.Cluster; @@ -63,6 +63,7 @@ public class StackVersionListenerTest extends EasyMockSupport { private static final String UNKNOWN_VERSION = "UNKNOWN"; private static final String VALID_PREVIOUS_VERSION = "2.2.0.0"; private static final RepositoryVersionEntity DUMMY_REPOSITORY_VERSION_ENTITY = new RepositoryVersionEntity(); + private static final HostVersionEntity DUMMY_HOST_VERSION_ENTITY = new HostVersionEntity(); private static final UpgradeEntity DUMMY_UPGRADE_ENTITY = new UpgradeEntity(); public static final String STACK_NAME = "HDP-2.4.0.0"; public static final String STACK_VERSION = "2.4.0.0"; @@ -72,7 +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; @@ -91,14 +91,6 @@ public class StackVersionListenerTest extends EasyMockSupport { 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.getService(SERVICE_NAME)).andReturn(service).atLeastOnce(); @@ -139,7 +131,7 @@ public class StackVersionListenerTest extends EasyMockSupport { expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE); sch.setVersion(VALID_NEW_VERSION); expectLastCall().once(); - expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once(); + expect(sch.recalculateHostVersionState()).andReturn(DUMMY_HOST_VERSION_ENTITY).once(); replayAll(); @@ -152,7 +144,7 @@ public class StackVersionListenerTest extends EasyMockSupport { expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE); sch.setVersion(VALID_NEW_VERSION); expectLastCall().once(); - expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once(); + expect(sch.recalculateHostVersionState()).andReturn(DUMMY_HOST_VERSION_ENTITY).once(); replayAll(); @@ -182,7 +174,7 @@ public class StackVersionListenerTest extends EasyMockSupport { expectLastCall().once(); sch.setVersion(VALID_NEW_VERSION); expectLastCall().once(); - expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once(); + expect(sch.recalculateHostVersionState()).andReturn(DUMMY_HOST_VERSION_ENTITY).once(); replayAll(); @@ -208,6 +200,8 @@ public class StackVersionListenerTest extends EasyMockSupport { @Test public void testSetUpgradeStateToCompleteWhenUpgradeIsInProgressAndNewVersionIsEqualToComponentDesiredVersion() { + expect(cluster.getUpgradeInProgress()).andReturn(DUMMY_UPGRADE_ENTITY); + expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION); expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS); expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE); @@ -221,6 +215,20 @@ public class StackVersionListenerTest extends EasyMockSupport { } @Test + public void testSetUpgradeStateToNoneWhenNoUpgradeAndNewVersionIsEqualToComponentDesiredVersion() { + expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION); + expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS); + expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE); + sch.setUpgradeState(UpgradeState.NONE); + expectLastCall().once(); + + expect(serviceComponent.getDesiredVersion()).andStubReturn(VALID_NEW_VERSION); + replayAll(); + + sendEventAndVerify(VALID_NEW_VERSION); + } + + @Test public void testSetUpgradeStateToVersionMismatchWhenUpgradeIsInProgressAndNewVersionIsNotEqualToComponentDesiredVersion() { expect(sch.getVersion()).andReturn(VALID_PREVIOUS_VERSION); expect(sch.getUpgradeState()).andReturn(UpgradeState.IN_PROGRESS); @@ -228,6 +236,9 @@ public class StackVersionListenerTest extends EasyMockSupport { sch.setUpgradeState(UpgradeState.VERSION_MISMATCH); expectLastCall().once(); + sch.setVersion(VALID_NEW_VERSION); + expectLastCall().once(); + expect(serviceComponent.getDesiredVersion()).andStubReturn(VALID_PREVIOUS_VERSION); replayAll(); http://git-wip-us.apache.org/repos/asf/ambari/blob/a2632675/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 6f06f43..38c9d1c 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 @@ -26,10 +26,8 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.lang.reflect.Field; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -110,7 +108,6 @@ import org.apache.commons.lang.StringUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentCaptor; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -443,12 +440,14 @@ public class ClusterTest { * @param hostAttributes Host Attributes * @throws Exception */ - private void addHost(String hostName, Map<String, String> hostAttributes) throws Exception { + private Host addHost(String hostName, Map<String, String> hostAttributes) throws Exception { clusters.addHost(hostName); Host host = clusters.getHost(hostName); host.setIPv4("ipv4"); host.setIPv6("ipv6"); host.setHostAttributes(hostAttributes); + + return host; } /** @@ -1640,14 +1639,16 @@ public class ClusterTest { } /** - * Comprehensive test for transitionHostVersion and recalculateClusterVersion. - * It creates a cluster with 3 hosts and 3 services, one of which does not advertise a version. - * It then verifies that all 3 hosts have a version of CURRENT, and so does the cluster. - * It then adds one more host with a component, so its HostVersion will initialize in CURRENT. - * Next, it distributes a repo so that it is INSTALLED on the 4 hosts. - * It then adds one more host, whose HostVersion will be OUT_OF_SYNC for the new repo. - * After redistributing bits again, it simulates an RU. - * Finally, some of the hosts will end up with a HostVersion in UPGRADED, and others still in INSTALLED. + * Comprehensive test for host versions. It creates a cluster with 3 hosts and + * 3 services, one of which does not advertise a version. It then verifies + * that all 3 hosts have a version of CURRENT, and so does the cluster. It + * then adds one more host with a component, so its HostVersion will + * initialize in CURRENT. Next, it distributes a repo so that it is INSTALLED + * on the 4 hosts. It then adds one more host, whose HostVersion will be + * OUT_OF_SYNC for the new repo. After redistributing bits again, it simulates + * an RU. Finally, some of the hosts will end up with a HostVersion in + * UPGRADED, and others still in INSTALLED. + * * @throws Exception */ @Test @@ -1736,13 +1737,21 @@ public class ClusterTest { // Add one more Host, with only Ganglia on it. It should have a HostVersion in NOT_REQUIRED for v2, // as Ganglia isn't versionable - addHost("h-5", hostAttributes); + Host host5 = addHost("h-5", hostAttributes); clusters.mapAndPublishHostsToCluster(Collections.singleton("h-5"), clusterName); + + // verify that the new host version was added for the existing repo + HostVersionEntity h5Version1 = hostVersionDAO.findHostVersionByHostAndRepository(host5.getHostEntity(), rv1); + HostVersionEntity h5Version2 = hostVersionDAO.findHostVersionByHostAndRepository(host5.getHostEntity(), rv2); + + Assert.assertEquals(RepositoryVersionState.NOT_REQUIRED, h5Version1.getState()); + Assert.assertEquals(RepositoryVersionState.NOT_REQUIRED, h5Version2.getState()); + ServiceComponentHost schHost5Serv3CompB = serviceComponentHostFactory.createNew(sc3CompB, "h-5"); sc3CompB.addServiceComponentHost(schHost5Serv3CompB); // 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"); + h5Version2 = hostVersionDAO.findByClusterStackVersionAndHost(clusterName, stackId, v2, "h-5"); Assert.assertNotNull(h5Version2); Assert.assertEquals(RepositoryVersionState.NOT_REQUIRED, h5Version2.getState()); @@ -1897,84 +1906,13 @@ public class ClusterTest { List<HostVersionEntity> entities = hostVersionDAO.findByClusterAndHost(clusterName, "h-3"); assertTrue("Expected no host versions", null == entities || 0 == entities.size()); - c1.transitionHostVersionState(hostEntity, repositoryVersion, c1.getDesiredStackVersion()); + List<ServiceComponentHost> componentsOnHost3 = c1.getServiceComponentHosts("h-3"); + componentsOnHost3.iterator().next().recalculateHostVersionState(); entities = hostVersionDAO.findByClusterAndHost(clusterName, "h-3"); - assertEquals(1, entities.size()); } - @Test - public void testTransitionHostVersionState_OutOfSync_BlankCurrent() throws Exception { - /** - * Checks case when there are 2 cluster stack versions present (CURRENT and OUT_OF_SYNC), - * and we add a new host to cluster. On a new host, both CURRENT and OUT_OF_SYNC host - * versions should be present - */ - StackId stackId = new StackId("HDP-2.0.5"); - String clusterName = "c1"; - clusters.addCluster(clusterName, stackId); - final Cluster c1 = clusters.getCluster(clusterName); - Assert.assertEquals(clusterName, c1.getClusterName()); - - clusters.addHost("h-1"); - clusters.addHost("h-2"); - String h3 = "h-3"; - clusters.addHost(h3); - - for (String hostName : new String[] { "h-1", "h-2", h3}) { - Host h = clusters.getHost(hostName); - h.setIPv4("ipv4"); - h.setIPv6("ipv6"); - - Map<String, String> hostAttributes = new HashMap<>(); - hostAttributes.put("os_family", "redhat"); - hostAttributes.put("os_release_version", "5.9"); - h.setHostAttributes(hostAttributes); - } - - String v1 = "2.0.5-1"; - String v2 = "2.0.5-2"; - c1.setDesiredStackVersion(stackId); - RepositoryVersionEntity rve1 = helper.getOrCreateRepositoryVersion(stackId, - v1); - RepositoryVersionEntity rve2 = helper.getOrCreateRepositoryVersion(stackId, - v2); - - c1.setCurrentStackVersion(stackId); - - clusters.mapHostToCluster("h-1", clusterName); - clusters.mapHostToCluster("h-2", clusterName); - - RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(c1); - - Service service = c1.addService("ZOOKEEPER", repositoryVersion); - ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER"); - sc.addServiceComponentHost("h-1"); - sc.addServiceComponentHost("h-2"); - - clusters.mapHostToCluster(h3, clusterName); - - // This method is usually called when we receive heartbeat from new host - HostEntity hostEntity3 = mock(HostEntity.class); - when(hostEntity3.getHostName()).thenReturn(h3); - - // HACK: to workaround issue with NullPointerException at - // org.eclipse.persistence.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:1037) - // during hostVersionDAO.merge() - HostVersionDAO hostVersionDAOMock = mock(HostVersionDAO.class); - Field field = ClusterImpl.class.getDeclaredField("hostVersionDAO"); - field.setAccessible(true); - field.set(c1, hostVersionDAOMock); - - ArgumentCaptor<HostVersionEntity> hostVersionCaptor = ArgumentCaptor.forClass(HostVersionEntity.class); - - c1.transitionHostVersionState(hostEntity3, rve1, stackId); - - verify(hostVersionDAOMock).merge(hostVersionCaptor.capture()); - assertEquals(hostVersionCaptor.getValue().getState(), RepositoryVersionState.CURRENT); - } - /** * Tests that an existing configuration can be successfully updated without * creating a new version.
