You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/10/12 00:12:14 UTC
svn commit: r1397336 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/
ambari-server/src/main/java/org/apache/ambari/server/state/
ambari-server/src/main/java/org/apache/ambari/server/state/...
Author: hitesh
Date: Thu Oct 11 22:12:13 2012
New Revision: 1397336
URL: http://svn.apache.org/viewvc?rev=1397336&view=rev
Log:
AMBARI-848. Various tests for FSM and Controller impl. (Contributed by hitesh)
Added:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java (with props)
Removed:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceProviderImplTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Thu Oct 11 22:12:13 2012
@@ -11,6 +11,8 @@ AMBARI-666 branch (unreleased changes)
INCOMPATIBLE CHANGES
NEW FEATURES
+
+ AMBARI-848. Various tests for FSM and Controller impl. (hitesh)
AMBARI-847. Run pyunit tests from maven test target and also autogenerated
openssl passphrase. (mahadev)
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Thu Oct 11 22:12:13 2012
@@ -19,6 +19,7 @@
package org.apache.ambari.server.controller;
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.HostNotFoundException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.actionmanager.ActionManager;
@@ -254,14 +255,14 @@ public class AmbariManagementControllerI
);
}
- Host h = clusters.getHost(request.getHostname());
- if (h == null) {
- // FIXME throw correct error as not bootstrapped
+ Host h = null;
+ try {
+ h = clusters.getHost(request.getHostname());
+ }
+ catch (HostNotFoundException e) {
+ throw new AmbariException("Host has not be registered with the server"
+ + ", hostname=" + request.getHostname());
}
- // TODO should agent registration create entry in the DB or should we
- // re-think schema to allow simple new entry
-
- clusters.addHost(request.getHostname());
if (request.getClusterNames() != null) {
for (String clusterName : request.getClusterNames()) {
@@ -290,7 +291,7 @@ public class AmbariManagementControllerI
// FIXME throw correct error
throw new AmbariException("Invalid arguments");
}
-
+
// FIXME Hard coded stuff --- needs to be fixed.
if (request.getServiceName() == null
|| request.getServiceName().isEmpty()
@@ -687,8 +688,7 @@ public class AmbariManagementControllerI
final Service s = cluster.getService(request.getServiceName());
if (request.getConfigVersions() != null) {
- // TODO
- // handle config updates
+ // TODO handle config updates
// handle recursive updates to all components and hostcomponents
// if different from old desired configs, trigger relevant actions
throw new AmbariException("Unsupported operation - config updates not"
@@ -905,8 +905,7 @@ public class AmbariManagementControllerI
request.getComponentName());
if (request.getConfigVersions() != null) {
- // TODO
- // handle config updates
+ // TODO handle config updates
// handle recursive updates to all components and hostcomponents
// if different from old desired configs, trigger relevant actions
throw new AmbariException("Unsupported operation - config updates not"
@@ -1075,8 +1074,7 @@ public class AmbariManagementControllerI
request.getHostname());
if (request.getConfigVersions() != null) {
- // TODO
- // handle config updates
+ // TODO handle config updates
// handle recursive updates to all components and hostcomponents
// if different from old desired configs, trigger relevant actions
throw new AmbariException("Unsupported operation - config updates not"
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java Thu Oct 11 22:12:13 2012
@@ -18,7 +18,7 @@
package org.apache.ambari.server.controller;
-import java.util.List;
+import java.util.Set;
/**
* Used for create Cluster
@@ -31,10 +31,10 @@ public class ClusterRequest {
private String stackVersion; // for CREATE/UPDATE
- List<String> hostNames; // CREATE/UPDATE
+ Set<String> hostNames; // CREATE/UPDATE
public ClusterRequest(Long clusterId, String clusterName,
- String stackVersion, List<String> hostNames) {
+ String stackVersion, Set<String> hostNames) {
super();
this.clusterId = clusterId;
this.clusterName = clusterName;
@@ -84,14 +84,15 @@ public class ClusterRequest {
this.stackVersion = stackVersion;
}
- public List<String> getHostNames() {
+ public Set<String> getHostNames() {
return hostNames;
}
- public void setHostNames(List<String> hostNames) {
+ public void setHostNames(Set<String> hostNames) {
this.hostNames = hostNames;
}
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{"
@@ -99,11 +100,13 @@ public class ClusterRequest {
+ ", clusterId=" + clusterId
+ ", hosts=[");
if (hostNames != null) {
- for (int i = 0; i < hostNames.size(); ++i) {
+ int i = 0;
+ for (String hostName : hostNames) {
if (i != 0) {
sb.append(",");
}
- sb.append(hostNames.get(i));
+ ++i;
+ sb.append(hostName);
}
}
sb.append("] }");
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java Thu Oct 11 22:12:13 2012
@@ -26,9 +26,10 @@ public class ClusterResponse {
private final String clusterName;
- private Set<String> hostNames;
+ private final Set<String> hostNames;
- public ClusterResponse(Long clusterId, String clusterName, Set<String> hostNames) {
+ public ClusterResponse(Long clusterId, String clusterName,
+ Set<String> hostNames) {
super();
this.clusterId = clusterId;
this.clusterName = clusterName;
@@ -55,4 +56,25 @@ public class ClusterResponse {
public Set<String> getHostNames() {
return hostNames;
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{"
+ + " clusterName=" + clusterName
+ + ", clusterId=" + clusterId
+ + ", hosts=[");
+ if (hostNames != null) {
+ int i = 0;
+ for (String hostName : hostNames) {
+ if (i != 0) {
+ sb.append(",");
+ }
+ ++i;
+ sb.append(hostName);
+ }
+ }
+ sb.append("] }");
+ return sb.toString();
+ }
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java Thu Oct 11 22:12:13 2012
@@ -91,7 +91,7 @@ public interface Clusters {
throws AmbariException;
- public void mapHostsToCluster(List<String> hostnames, String clusterName)
+ public void mapHostsToCluster(Set<String> hostnames, String clusterName)
throws AmbariException;
public void debugDump(StringBuilder sb);
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java Thu Oct 11 22:12:13 2012
@@ -103,6 +103,9 @@ public class ClustersImpl implements Clu
@Override
public synchronized Host getHost(String hostname) throws AmbariException {
+ if (!hosts.containsKey(hostname)) {
+ throw new HostNotFoundException(hostname);
+ }
return hosts.get(hostname);
}
@@ -143,7 +146,7 @@ public class ClustersImpl implements Clu
}
@Override
- public synchronized void mapHostsToCluster(List<String> hostnames,
+ public synchronized void mapHostsToCluster(Set<String> hostnames,
String clusterName) throws AmbariException {
Cluster c = getCluster(clusterName);
for (String hostname : hostnames) {
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java Thu Oct 11 22:12:13 2012
@@ -56,7 +56,7 @@ public class TestHeartbeatHandler {
assertEquals(HostState.HEALTHY, hostObject.getState());
assertEquals(0, aq.dequeueAll(hostname).size());
}
-
+
@Test
public void testRegistration() throws AmbariException,
InvalidStateTransitonException {
@@ -67,7 +67,7 @@ public class TestHeartbeatHandler {
HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am);
Host hostObject = new HostImpl(hostname);
when(fsm.getHost(hostname)).thenReturn(hostObject);
-
+
Register reg = new Register();
HostInfo hi = new HostInfo();
hi.setOS("MegaOperatingSystem");
@@ -77,13 +77,14 @@ public class TestHeartbeatHandler {
assertEquals(hostObject.getState(), HostState.HEALTHY);
assertEquals("MegaOperatingSystem", hostObject.getOsType());
}
-
+
@Test
public void testRegisterNewNode() throws AmbariException, InvalidStateTransitonException {
ActionManager am = new ActionManager(0, 0, null, null,
new ActionDBInMemoryImpl());
Clusters fsm = new ClustersImpl();
String hostname = "host1";
+ fsm.addHost(hostname);
HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am);
Register reg = new Register();
HostInfo hi = new HostInfo();
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Thu Oct 11 22:12:13 2012
@@ -20,7 +20,10 @@ package org.apache.ambari.server.control
import static org.junit.Assert.fail;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import junit.framework.Assert;
@@ -50,11 +53,12 @@ public class AmbariManagementControllerT
private AmbariManagementController controller;
private Clusters clusters;
- private ActionDBAccessor db = new ActionDBInMemoryImpl();
+ private ActionDBAccessor db;
@Before
public void setup() {
clusters = new ClustersImpl();
+ db = new ActionDBInMemoryImpl();
ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(),
clusters, db);
controller = new AmbariManagementControllerImpl(am, clusters);
@@ -64,6 +68,7 @@ public class AmbariManagementControllerT
public void teardown() {
controller = null;
clusters = null;
+ db = null;
}
private void createCluster(String clusterName) throws AmbariException {
@@ -301,6 +306,47 @@ public class AmbariManagementControllerT
@Test
public void testCreateHost() throws AmbariException {
+ List<String> clusterNames = null;
+ Map<String, String> hostAttributes = null;
+
+ HostRequest r1 = new HostRequest("h1", clusterNames, hostAttributes);
+ r1.toString();
+ try {
+ controller.createHost(r1);
+ fail("Create host should fail for non-bootstrapped host");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addHost("h1");
+ clusters.addHost("h2");
+
+ controller.createHost(r1);
+
+ clusterNames = new ArrayList<String>();
+ clusterNames.add("foo1");
+ clusterNames.add("foo2");
+
+ hostAttributes = new HashMap<String, String>();
+ HostRequest r2 = new HostRequest("h2", clusterNames, hostAttributes);
+
+ try {
+ controller.createHost(r2);
+ fail("Create host should fail for invalid clusters");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addCluster("foo1");
+ clusters.addCluster("foo2");
+
+ controller.createHost(r2);
+
+ Assert.assertNotNull(clusters.getHost("h1"));
+ Assert.assertNotNull(clusters.getHost("h2"));
+
+ Assert.assertEquals(0, clusters.getClustersForHost("h1").size());
+ Assert.assertEquals(2, clusters.getClustersForHost("h2").size());
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java?rev=1397336&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java Thu Oct 11 22:12:13 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.controller;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.ambari.server.state.StackVersion;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ClusterRequestTest {
+
+ @Test
+ public void testBasicGetAndSet() {
+ Long clusterId = new Long(10);
+ String clusterName = "foo";
+ StackVersion stackVersion = new StackVersion("1.0.1");
+ Set<String> hostNames = new HashSet<String>();
+ hostNames.add("h1");
+
+ ClusterRequest r1 =
+ new ClusterRequest(clusterId, clusterName,
+ stackVersion.getStackVersion(), hostNames);
+
+ Assert.assertEquals(clusterId, r1.getClusterId());
+ Assert.assertEquals(clusterName, r1.getClusterName());
+ Assert.assertEquals(stackVersion.getStackVersion(),
+ r1.getStackVersion());
+ Assert.assertArrayEquals(hostNames.toArray(), r1.getHostNames().toArray());
+
+ r1.setClusterId(++clusterId);
+ r1.setHostNames(hostNames);
+ r1.setClusterName("foo1");
+ r1.setStackVersion("1.0.2");
+
+ hostNames.add("h2");
+
+ Assert.assertEquals(clusterId, r1.getClusterId());
+ Assert.assertEquals("foo1", r1.getClusterName());
+ Assert.assertEquals("1.0.2", r1.getStackVersion());
+ Assert.assertArrayEquals(hostNames.toArray(), r1.getHostNames().toArray());
+
+ }
+
+ @Test
+ public void testToString() {
+ ClusterRequest r1 = new ClusterRequest(null, null, null, null);
+ r1.toString();
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterRequestTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java?rev=1397336&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java Thu Oct 11 22:12:13 2012
@@ -0,0 +1,32 @@
+package org.apache.ambari.server.controller;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ClusterResponseTest {
+
+ @Test
+ public void testBasicGetAndSet() {
+ Long clusterId = new Long(10);
+ String clusterName = "foo";
+ Set<String> hostNames = new HashSet<String>();
+ hostNames.add("h1");
+
+ ClusterResponse r1 =
+ new ClusterResponse(clusterId, clusterName, hostNames);
+
+ Assert.assertEquals(clusterId, r1.getClusterId());
+ Assert.assertEquals(clusterName, r1.getClusterName());
+ Assert.assertArrayEquals(hostNames.toArray(), r1.getHostNames().toArray());
+
+ }
+
+ @Test
+ public void testToString() {
+ ClusterResponse r = new ClusterResponse(null, null, null);
+ r.toString();
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceProviderImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceProviderImplTest.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceProviderImplTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceProviderImplTest.java Thu Oct 11 22:12:13 2012
@@ -435,7 +435,7 @@ public class ResourceProviderImplTest {
public static class Matchers
{
- public static ClusterRequest clusterRequest(Long clusterId, String clusterName, String stackVersion, List<String> hostNames)
+ public static ClusterRequest clusterRequest(Long clusterId, String clusterName, String stackVersion, Set<String> hostNames)
{
EasyMock.reportMatcher(new ClusterRequestMatcher(clusterId, clusterName, stackVersion, hostNames));
return null;
@@ -457,7 +457,7 @@ public class ResourceProviderImplTest {
public static class ClusterRequestMatcher extends ClusterRequest implements IArgumentMatcher {
- public ClusterRequestMatcher(Long clusterId, String clusterName, String stackVersion, List<String> hostNames) {
+ public ClusterRequestMatcher(Long clusterId, String clusterName, String stackVersion, Set<String> hostNames) {
super(clusterId, clusterName, stackVersion, hostNames);
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java?rev=1397336&r1=1397335&r2=1397336&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java Thu Oct 11 22:12:13 2012
@@ -31,7 +31,7 @@ public class ServiceTest {
private Clusters clusters;
private Cluster cluster;
private String clusterName;
-
+
@Before
public void setup() throws AmbariException {
clusters = new ClustersImpl();
@@ -40,20 +40,20 @@ public class ServiceTest {
cluster = clusters.getCluster(clusterName);
Assert.assertNotNull(cluster);
}
-
+
@After
public void teardown() throws AmbariException {
clusters = null;
- cluster = null;
+ cluster = null;
}
-
+
@Test
public void testCreateService() throws AmbariException {
String serviceName = "s1";
Service s = new ServiceImpl(cluster, serviceName);
cluster.addService(s);
Service service = cluster.getService(serviceName);
-
+
Assert.assertNotNull(service);
Assert.assertEquals(serviceName, service.getName());
Assert.assertEquals(cluster.getClusterId(),
@@ -71,23 +71,23 @@ public class ServiceTest {
Service s = new ServiceImpl(cluster, serviceName);
cluster.addService(s);
Service service = cluster.getService(serviceName);
-
+
Assert.assertNotNull(service);
service.setDesiredStackVersion(new StackVersion("1.1.0"));
Assert.assertEquals("1.1.0",
service.getDesiredStackVersion().getStackVersion());
-
-
+
+
service.setDesiredState(State.INSTALLING);
Assert.assertEquals(State.INSTALLING, service.getDesiredState());
-
+
}
-
-
-
+
+
+
/*
-
+
public ServiceComponent getServiceComponent(String componentName)
@@ -116,7 +116,7 @@ public class ServiceTest {
public void setStackVersion(StackVersion stackVersion);
public ServiceResponse convertToResponse();
-
-
+
+
*/
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java?rev=1397336&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java Thu Oct 11 22:12:13 2012
@@ -0,0 +1,203 @@
+/**
+ * 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.state.cluster;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.agent.DiskInfo;
+import org.apache.ambari.server.agent.HostInfo;
+import org.apache.ambari.server.controller.ClusterResponse;
+import org.apache.ambari.server.state.AgentVersion;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.StackVersion;
+import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
+import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClusterTest {
+
+ private Clusters clusters;
+ private Cluster c1;
+ String h1 = "h1";
+ String s1 = "s1";
+ String sc1 = "sc1";
+
+ @Before
+ public void setup() throws AmbariException {
+ clusters = new ClustersImpl();
+ clusters.addCluster("c1");
+ c1 = clusters.getCluster("c1");
+ Assert.assertEquals("c1", c1.getClusterName());
+ clusters.addHost(h1);
+ clusters.mapHostToCluster(h1, "c1");
+ }
+
+ @After
+ public void teardown() {
+ clusters = null;
+ c1 = null;
+ }
+
+ @Test
+ public void testAddHost() throws AmbariException {
+ clusters.addHost("h2");
+
+ try {
+ clusters.addHost("h2");
+ fail("Duplicate add should fail");
+ }
+ catch (AmbariException e) {
+ // Expected
+ }
+
+ }
+
+
+ @Test
+ public void testGetHostState() throws AmbariException {
+ Assert.assertEquals(HostState.INIT, clusters.getHost(h1).getState());
+ }
+
+ @Test
+ public void testSetHostState() throws AmbariException {
+ clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+ Assert.assertEquals(HostState.HEARTBEAT_LOST,
+ clusters.getHost(h1).getState());
+ }
+
+ @Test
+ public void testHostEvent() throws AmbariException,
+ InvalidStateTransitonException {
+ HostInfo hostInfo = new HostInfo();
+ hostInfo.setHostName(h1);
+ hostInfo.setInterfaces("fip_4");
+ hostInfo.setArchitecture("os_arch");
+ hostInfo.setOS("os_type");
+ hostInfo.setMemoryTotal(10);
+ hostInfo.setMemorySize(100);
+ hostInfo.setProcessorCount(10);
+ List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+ mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
+ "5000000", "4000000", "10%", "size"));
+ hostInfo.setMounts(mounts);
+
+ AgentVersion agentVersion = new AgentVersion("0.0.x");
+ long currentTime = 1001;
+
+ clusters.getHost(h1).handleEvent(new HostRegistrationRequestEvent(
+ h1, agentVersion, currentTime, hostInfo));
+
+ Assert.assertEquals(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+ clusters.getHost(h1).getState());
+
+ clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+
+ try {
+ clusters.getHost(h1).handleEvent(
+ new HostHealthyHeartbeatEvent(h1, currentTime));
+ fail("Exception should be thrown on invalid event");
+ }
+ catch (InvalidStateTransitonException e) {
+ // Expected
+ }
+
+ }
+
+ @Test
+ public void testBasicClusterSetup() throws AmbariException {
+ String clusterName = "c2";
+
+ try {
+ clusters.getCluster(clusterName);
+ fail("Exception expected for invalid cluster");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addCluster(clusterName);
+ Cluster c2 = clusters.getCluster(clusterName);
+
+ Assert.assertNotNull(c2);
+
+ Assert.assertEquals(clusterName.hashCode(), c2.getClusterId());
+ Assert.assertEquals(clusterName, c2.getClusterName());
+
+ c2.setClusterName("foo2");
+ Assert.assertEquals("foo2", c2.getClusterName());
+ Assert.assertEquals(clusterName.hashCode(), c2.getClusterId());
+
+ Assert.assertNotNull(c2.getDesiredStackVersion());
+ Assert.assertEquals("", c2.getDesiredStackVersion().getStackVersion());
+
+ StackVersion stackVersion = new StackVersion("1.0");
+ c2.setDesiredStackVersion(stackVersion);
+ Assert.assertEquals("1.0", c2.getDesiredStackVersion().getStackVersion());
+ }
+
+ @Test
+ public void testAddAndGetServices() {
+ // TODO write unit tests for
+ // public void addService(Service service) throws AmbariException;
+ // public Service getService(String serviceName) throws AmbariException;
+ // public Map<String, Service> getServices();
+ }
+
+
+ @Test
+ public void testGetServiceComponentHosts() {
+ // TODO write unit tests
+ // public List<ServiceComponentHost> getServiceComponentHosts(String hostname);
+ }
+
+
+ @Test
+ public void testGetAndSetConfigs() {
+ // TODO write unit tests
+ // public Map<String, Config> getConfigsByType(String configType);
+ // public Config getConfig(String configType, String versionTag);
+ // public void addConfig(Config config);
+ }
+
+ @Test
+ public void testConvertToResponse() {
+ // TODO write unit tests
+ }
+
+ @Test
+ public void testDebugDump() {
+ // TODO write unit tests
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java?rev=1397336&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java Thu Oct 11 22:12:13 2012
@@ -0,0 +1,188 @@
+/**
+ * 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.state.cluster;
+
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClustersTest {
+
+ private Clusters clusters;
+
+ @Before
+ public void setup() {
+ clusters = new ClustersImpl();
+ }
+
+ @After
+ public void teardown() {
+ clusters = null;
+ }
+
+ @Test
+ public void testGetInvalidCluster() throws AmbariException {
+ try {
+ clusters.getCluster("foo");
+ fail("Exception should be thrown on invalid get");
+ }
+ catch (ClusterNotFoundException e) {
+ // Expected
+ }
+
+ }
+
+ @Test
+ public void testAddAndGetCluster() throws AmbariException {
+
+ String c1 = "foo";
+ String c2 = "foo";
+ clusters.addCluster(c1);
+
+ try {
+ clusters.addCluster(c1);
+ fail("Exception should be thrown on invalid add");
+ }
+ catch (AmbariException e) {
+ // Expected
+ }
+
+ try {
+ clusters.addCluster(c2);
+ fail("Exception should be thrown on invalid add");
+ }
+ catch (AmbariException e) {
+ // Expected
+ }
+
+ c2 = "foo2";
+ clusters.addCluster(c2);
+
+ Assert.assertNotNull(clusters.getCluster(c1));
+ Assert.assertNotNull(clusters.getCluster(c2));
+
+ Assert.assertEquals(c1, clusters.getCluster(c1).getClusterName());
+ Assert.assertEquals(c2, clusters.getCluster(c2).getClusterName());
+
+ Map<String, Cluster> verifyClusters = clusters.getClusters();
+ Assert.assertTrue(verifyClusters.containsKey(c1));
+ Assert.assertTrue(verifyClusters.containsKey(c2));
+ Assert.assertNotNull(verifyClusters.get(c1));
+ Assert.assertNotNull(verifyClusters.get(c2));
+
+ }
+
+
+ @Test
+ public void testAddAndGetHost() throws AmbariException {
+ String h1 = "h1";
+ String h2 = "h2";
+ String h3 = "h3";
+
+ clusters.addHost(h1);
+
+ try {
+ clusters.addHost(h1);
+ fail("Expected exception on duplicate host entry");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addHost(h2);
+ clusters.addHost(h3);
+
+ List<Host> hosts = clusters.getHosts();
+ Assert.assertEquals(3, hosts.size());
+
+ Assert.assertNotNull(clusters.getHost(h1));
+ Assert.assertNotNull(clusters.getHost(h2));
+ Assert.assertNotNull(clusters.getHost(h3));
+
+ }
+
+ @Test
+ public void testClusterHostMapping() throws AmbariException {
+ String c1 = "c1";
+ String c2 = "c2";
+ String h1 = "h1";
+ String h2 = "h2";
+ String h3 = "h3";
+
+ try {
+ clusters.mapHostToCluster(h1, c1);
+ fail("Expected exception for invalid cluster/host");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addCluster(c1);
+ clusters.addCluster(c2);
+ Assert.assertNotNull(clusters.getCluster(c1));
+ Assert.assertNotNull(clusters.getCluster(c2));
+ try {
+ clusters.mapHostToCluster(h1, c1);
+ fail("Expected exception for invalid host");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addHost(h1);
+ clusters.addHost(h2);
+ clusters.addHost(h3);
+ Assert.assertNotNull(clusters.getHost(h1));
+
+ clusters.mapHostToCluster(h1, c1);
+ clusters.mapHostToCluster(h1, c2);
+ clusters.mapHostToCluster(h2, c1);
+ clusters.mapHostToCluster(h2, c2);
+ clusters.mapHostToCluster(h1, c2);
+
+ Set<Cluster> c = clusters.getClustersForHost(h3);
+ Assert.assertEquals(0, c.size());
+
+ c = clusters.getClustersForHost(h1);
+ Assert.assertEquals(2, c.size());
+
+ c = clusters.getClustersForHost(h2);
+ Assert.assertEquals(2, c.size());
+
+ // TODO write test for mapHostsToCluster
+
+ }
+
+ @Test
+ public void testDebugDump() {
+ // TODO write unit test
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
------------------------------------------------------------------------------
svn:eol-style = native