|
@@ -72,6 +72,7 @@ import org.junit.Test;
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
/**
|
|
|
* AmbariContext unit tests
|
|
@@ -200,6 +201,9 @@ public class AmbariContextTest {
|
|
|
expect(clusters.getHost(HOST1)).andReturn(host1).anyTimes();
|
|
|
expect(clusters.getHost(HOST2)).andReturn(host2).anyTimes();
|
|
|
|
|
|
+ Map<String, Host> clusterHosts = ImmutableMap.of(HOST1, host1, HOST2, host2);
|
|
|
+ expect(clusters.getHostsForCluster(CLUSTER_NAME)).andReturn(clusterHosts).anyTimes();
|
|
|
+
|
|
|
expect(cluster.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
|
|
|
expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
|
|
|
|
|
@@ -358,6 +362,54 @@ public class AmbariContextTest {
|
|
|
assertEquals("val3", requestProps.get("prop3"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testRegisterHostWithConfigGroup_createNewConfigGroupWithPendingHosts() throws Exception {
|
|
|
+ // test specific expectations
|
|
|
+ expect(cluster.getConfigGroups()).andReturn(Collections.<Long, ConfigGroup>emptyMap()).once();
|
|
|
+ expect(clusterController.ensureResourceProvider(Resource.Type.ConfigGroup)).andReturn(configGroupResourceProvider).once();
|
|
|
+ //todo: for now not using return value so just returning null
|
|
|
+ expect(configGroupResourceProvider.createResources(capture(configGroupRequestCapture))).andReturn(null).once();
|
|
|
+ configHelper.moveDeprecatedGlobals(stackId, group1Configuration.getFullProperties(1), CLUSTER_NAME);
|
|
|
+
|
|
|
+ reset(group1Info);
|
|
|
+ expect(group1Info.getConfiguration()).andReturn(group1Configuration).anyTimes();
|
|
|
+ Collection<String> groupHosts = ImmutableList.of(HOST1, HOST2, "pending_host"); // pending_host is not registered with the cluster
|
|
|
+ expect(group1Info.getHostNames()).andReturn(groupHosts).anyTimes(); // there are 3 hosts for the host group
|
|
|
+ // replay all mocks
|
|
|
+ replayAll();
|
|
|
+
|
|
|
+ // test
|
|
|
+ context.registerHostWithConfigGroup(HOST1, topology, HOST_GROUP_1);
|
|
|
+
|
|
|
+ // assertions
|
|
|
+ Set<ConfigGroupRequest> configGroupRequests = configGroupRequestCapture.getValue();
|
|
|
+ assertEquals(1, configGroupRequests.size());
|
|
|
+ ConfigGroupRequest configGroupRequest = configGroupRequests.iterator().next();
|
|
|
+ assertEquals(CLUSTER_NAME, configGroupRequest.getClusterName());
|
|
|
+ assertEquals("testBP:group1", configGroupRequest.getGroupName());
|
|
|
+ assertEquals("service1", configGroupRequest.getTag());
|
|
|
+ assertEquals("Host Group Configuration", configGroupRequest.getDescription());
|
|
|
+ Collection<String> requestHosts = configGroupRequest.getHosts();
|
|
|
+
|
|
|
+ // we expect only HOST1 and HOST2 in the config group request as the third host "pending_host" hasn't registered yet with the cluster
|
|
|
+ assertEquals(2, requestHosts.size());
|
|
|
+ assertTrue(requestHosts.contains(HOST1));
|
|
|
+ assertTrue(requestHosts.contains(HOST2));
|
|
|
+
|
|
|
+ Map<String, Config> requestConfig = configGroupRequest.getConfigs();
|
|
|
+ assertEquals(1, requestConfig.size());
|
|
|
+ Config type1Config = requestConfig.get("type1");
|
|
|
+ //todo: other properties such as cluster name are not currently being explicitly set on config
|
|
|
+ assertEquals("type1", type1Config.getType());
|
|
|
+ assertEquals("group1", type1Config.getTag());
|
|
|
+ Map<String, String> requestProps = type1Config.getProperties();
|
|
|
+ assertEquals(3, requestProps.size());
|
|
|
+ // 1.2 is overridden value
|
|
|
+ assertEquals("val1.2", requestProps.get("prop1"));
|
|
|
+ assertEquals("val2", requestProps.get("prop2"));
|
|
|
+ assertEquals("val3", requestProps.get("prop3"));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testRegisterHostWithConfigGroup_registerWithExistingConfigGroup() throws Exception {
|
|
|
// test specific expectations
|