You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/04/21 00:10:19 UTC
ambari git commit: AMBARI-10612. Fix broken unit tests on
builds.apache.org in TestActionScheduler and
AmbariManagementControllerImplTest (alejandro)
Repository: ambari
Updated Branches:
refs/heads/trunk e1d998f8c -> d9f6bbec2
AMBARI-10612. Fix broken unit tests on builds.apache.org in TestActionScheduler and AmbariManagementControllerImplTest (alejandro)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d9f6bbec
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d9f6bbec
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d9f6bbec
Branch: refs/heads/trunk
Commit: d9f6bbec2eeb275146eca739951664fd55c47cc1
Parents: e1d998f
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Mon Apr 20 14:03:50 2015 -0700
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Mon Apr 20 15:10:15 2015 -0700
----------------------------------------------------------------------
.../actionmanager/TestActionScheduler.java | 28 +++++++++++++++++++-
.../AmbariManagementControllerImplTest.java | 22 ++++++++++++---
2 files changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9f6bbec/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
index e565922..b0edc3e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
@@ -47,6 +47,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.google.inject.Inject;
+import com.google.inject.persist.PersistService;
import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
@@ -85,6 +86,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEve
import org.apache.ambari.server.utils.StageUtils;
import org.easymock.Capture;
import org.easymock.EasyMock;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -134,6 +136,12 @@ public class TestActionScheduler {
injector.injectMembers(this);
}
+ @After
+ public void teardown() {
+ injector.getInstance(PersistService.class).stop();
+ injector = null;
+ }
+
/**
* This test sends a new action to the action scheduler and verifies that the action
* shows up in the action queue.
@@ -262,6 +270,10 @@ public class TestActionScheduler {
when(host.getState()).thenReturn(HostState.HEALTHY);
when(host.getHostName()).thenReturn(hostname);
+ HostEntity hostEntity = new HostEntity();
+ hostEntity.setHostName(hostname);
+ hostDAO.create(hostEntity);
+
List<Stage> stages = new ArrayList<Stage>();
final Stage s = StageUtils.getATestStage(1, 977, hostname, CLUSTER_HOST_INFO,
"{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}");
@@ -1246,7 +1258,6 @@ public class TestActionScheduler {
when(scomp.getServiceComponentHost(anyString())).thenReturn(sch);
when(serviceObj.getCluster()).thenReturn(oneClusterMock);
-
String host1 = "host1";
String host2 = "host2";
Host host = mock(Host.class);
@@ -1260,6 +1271,13 @@ public class TestActionScheduler {
when(host.getState()).thenReturn(HostState.HEALTHY);
when(host.getHostName()).thenReturn(host1);
+ HostEntity hostEntity1 = new HostEntity();
+ HostEntity hostEntity2 = new HostEntity();
+ hostEntity1.setHostName(host1);
+ hostEntity2.setHostName(host2);
+ hostDAO.create(hostEntity1);
+ hostDAO.create(hostEntity2);
+
final List<Stage> stages = new ArrayList<Stage>();
long now = System.currentTimeMillis();
@@ -1779,6 +1797,10 @@ public class TestActionScheduler {
hosts.put(hostname1, sch1);
when(scomp.getServiceComponentHosts()).thenReturn(hosts);
+ HostEntity hostEntity = new HostEntity();
+ hostEntity.setHostName(hostname1);
+ hostDAO.create(hostEntity);
+
UnitOfWork unitOfWork = mock(UnitOfWork.class);
when(fsm.getCluster(anyString())).thenReturn(oneClusterMock);
when(oneClusterMock.getService(anyString())).thenReturn(serviceObj);
@@ -1955,6 +1977,10 @@ public class TestActionScheduler {
when(scomp.getServiceComponentHost(anyString())).thenReturn(sch);
when(serviceObj.getCluster()).thenReturn(oneClusterMock);
+ HostEntity hostEntity = new HostEntity();
+ hostEntity.setHostName(hostname);
+ hostDAO.create(hostEntity);
+
HashMap<String, ServiceComponentHost> hosts =
new HashMap<String, ServiceComponentHost>();
hosts.put(hostname, sch);
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9f6bbec/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index 5778434..b062001 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -39,7 +39,10 @@ import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.RequestStageContainer;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.LdapSyncSpecEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.security.authorization.Users;
import org.apache.ambari.server.security.ldap.AmbariLdapDataPopulator;
import org.apache.ambari.server.security.ldap.LdapBatchDto;
@@ -1776,6 +1779,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testCreateDefaultHostParams() throws Exception {
+ String clusterName = "c1";
String SOME_STACK_NAME = "SomeStackName";
String SOME_STACK_VERSION = "1.0";
String MYSQL_JAR = "MYSQL_JAR";
@@ -1790,8 +1794,11 @@ public class AmbariManagementControllerImplTest {
Cluster cluster = createNiceMock(Cluster.class);
Injector injector = createNiceMock(Injector.class);
Configuration configuration = createNiceMock(Configuration.class);
+ ClusterVersionDAO clusterVersionDAO = createNiceMock(ClusterVersionDAO.class);
+ ClusterVersionEntity clusterVersionEntity = createNiceMock(ClusterVersionEntity.class);
+ RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
-
+ expect(cluster.getClusterName()).andReturn(clusterName);
expect(cluster.getDesiredStackVersion()).andReturn(stackId);
expect(stackId.getStackName()).andReturn(SOME_STACK_NAME).anyTimes();
expect(stackId.getStackVersion()).andReturn(SOME_STACK_VERSION).anyTimes();
@@ -1802,8 +1809,11 @@ public class AmbariManagementControllerImplTest {
expect(configuration.getOjdbcJarName()).andReturn(OJDBC_JAR_NAME);
expect(configuration.getServerDBName()).andReturn(SERVER_DB_NAME);
expect(configuration.getJavaVersion()).andReturn(8);
+ expect(clusterVersionDAO.findByClusterAndStateCurrent(clusterName)).andReturn(clusterVersionEntity).anyTimes();
+ expect(clusterVersionEntity.getRepositoryVersion()).andReturn(repositoryVersionEntity).anyTimes();
+ expect(repositoryVersionEntity.getVersion()).andReturn("1234").anyTimes();
- replay(manager, clusters, cluster, injector, stackId, configuration);
+ replay(manager, clusters, cluster, injector, stackId, configuration, clusterVersionDAO, clusterVersionEntity, repositoryVersionEntity);
AmbariManagementControllerImpl ambariManagementControllerImpl =
createMockBuilder(AmbariManagementControllerImpl.class)
@@ -1830,9 +1840,13 @@ public class AmbariManagementControllerImplTest {
f.setAccessible(true);
f.set(helper, configuration);
+ f = helperClass.getDeclaredField("clusterVersionDAO");
+ f.setAccessible(true);
+ f.set(helper, clusterVersionDAO);
+
Map<String, String> defaultHostParams = helper.createDefaultHostParams(cluster);
- assertEquals(defaultHostParams.size(), 11);
+ assertEquals(defaultHostParams.size(), 12);
assertEquals(defaultHostParams.get(DB_DRIVER_FILENAME), MYSQL_JAR);
assertEquals(defaultHostParams.get(STACK_NAME), SOME_STACK_NAME);
assertEquals(defaultHostParams.get(STACK_VERSION), SOME_STACK_VERSION);
@@ -1928,7 +1942,7 @@ public class AmbariManagementControllerImplTest {
}
@Test
- public void testVerifyRepositires() throws Exception {
+ public void testVerifyRepositories() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();