Skip to content

Commit

Permalink
AMBARI-25133. StackAdvisorAdapterTest result depends on method execut…
Browse files Browse the repository at this point in the history
…ion order (#2795)
  • Loading branch information
adoroszlai committed Jan 29, 2019
1 parent 402bf15 commit cf82327
Showing 1 changed file with 59 additions and 59 deletions.
Expand Up @@ -117,7 +117,7 @@ public class StackAdvisorAdapterTest {
.put("c7406", ImmutableSet.of("DATANODE", "HDFS_CLIENT", "ZOOKEEPER_CLIENT"))
.build();

private static final AddServiceInfo.Builder ADD_SERVICE_INFO_BUILDER = new AddServiceInfo.Builder()
private final AddServiceInfo.Builder addServiceInfoBuilder = new AddServiceInfo.Builder()
.setClusterName("c1");

@Test
Expand Down Expand Up @@ -168,58 +168,6 @@ public void mergeDisjunctMaps_invalidInput() {
StackAdvisorAdapter.mergeDisjunctMaps(map1, map2);
}

@Test
public void getLayoutRecommendationInfo() {
Map<String, Map<String, Set<String>>> newServices = ImmutableMap.of(
"KAFKA", ImmutableMap.of(
"KAFKA_BROKER", ImmutableSet.of("c7401")),
"SPARK2", ImmutableMap.of(
"SPARK2_JOBHISTORYSERVER", ImmutableSet.of("c7402"),
"SPARK2_CLIENT", ImmutableSet.of("c7403", "c7404")),
"OOZIE", ImmutableMap.of(
"OOZIE_SERVER", ImmutableSet.of("c7401"),
"OOZIE_CLIENT", ImmutableSet.of("c7403", "c7404")));

AddServiceRequest request = request(ConfigRecommendationStrategy.ALWAYS_APPLY);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
.setRequest(request)
.setStack(stack)
.setConfig(Configuration.newEmpty())
.setNewServices(newServices)
.build(); // No LayoutReommendationInfo -> needs to be calculated

LayoutRecommendationInfo layoutRecommendationInfo = adapter.getLayoutRecommendationInfo(info);
layoutRecommendationInfo.getAllServiceLayouts();

assertEquals(
ImmutableMap.of(
"host_group_1", ImmutableSet.of("c7401"),
"host_group_2", ImmutableSet.of("c7402"),
"host_group_3", ImmutableSet.of("c7403", "c7404")),
layoutRecommendationInfo.getHostGroups());

assertEquals(
ImmutableMap.<String, Map<String, Set<String>>>builder()
.put("KAFKA", ImmutableMap.of(
"KAFKA_BROKER", ImmutableSet.of("c7401")))
.put("SPARK2", ImmutableMap.of(
"SPARK2_JOBHISTORYSERVER", ImmutableSet.of("c7402"),
"SPARK2_CLIENT", ImmutableSet.of("c7403", "c7404")))
.put("OOZIE", ImmutableMap.of(
"OOZIE_SERVER", ImmutableSet.of("c7401"),
"OOZIE_CLIENT", ImmutableSet.of("c7403", "c7404")))
.put("HDFS", ImmutableMap.of(
"NAMENODE", ImmutableSet.of("c7401"),
"HDFS_CLIENT", ImmutableSet.of("c7401", "c7402")))
.put("ZOOKEEPER", ImmutableMap.of(
"ZOOKEEPER_SERVER", ImmutableSet.of("c7401"),
"ZOOKEEPER_CLIENT", ImmutableSet.of("c7401", "c7402")))
.put("MAPREDUCE2", ImmutableMap.of(
"HISTORYSERVER", ImmutableSet.of("c7401")))
.build(),
layoutRecommendationInfo.getAllServiceLayouts());
}

@Test
public void keepNewServicesOnly() {
Map<String, Map<String, Set<String>>> newServices = ImmutableMap.of(
Expand Down Expand Up @@ -368,7 +316,7 @@ public void recommendLayout() {
"KAFKA",
ImmutableMap.of("KAFKA_BROKER", emptySet()));

AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setStack(stack)
.setConfig(Configuration.newEmpty())
.setNewServices(newServices)
Expand Down Expand Up @@ -404,7 +352,7 @@ public void recommendConfigurations_noLayoutInfo() {
clusterConfig.setParentConfiguration(stackConfig);

AddServiceRequest request = request(ConfigRecommendationStrategy.ALWAYS_APPLY);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(userConfig)
Expand Down Expand Up @@ -459,7 +407,7 @@ public void recommendConfigurations_alwaysApply() {

LayoutRecommendationInfo layoutRecommendationInfo = new LayoutRecommendationInfo(new HashMap<>(), new HashMap<>()); // contents doesn't matter for the test
AddServiceRequest request = request(ConfigRecommendationStrategy.ALWAYS_APPLY);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(userConfig)
Expand Down Expand Up @@ -515,7 +463,7 @@ public void recommendConfigurations_alwaysDoNotOverrideCustomValues() {

LayoutRecommendationInfo layoutRecommendationInfo = new LayoutRecommendationInfo(new HashMap<>(), new HashMap<>()); // contents doesn't matter for the test
AddServiceRequest request = request(ConfigRecommendationStrategy.ALWAYS_APPLY_DONT_OVERRIDE_CUSTOM_VALUES);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(userConfig)
Expand Down Expand Up @@ -576,7 +524,7 @@ public void recommendConfigurations_neverApply() {

LayoutRecommendationInfo layoutRecommendationInfo = new LayoutRecommendationInfo(new HashMap<>(), new HashMap<>()); // contents doesn't matter for the test
AddServiceRequest request = request(ConfigRecommendationStrategy.NEVER_APPLY);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(userConfig)
Expand Down Expand Up @@ -623,7 +571,7 @@ public void recommendConfigurations_onlyStackDefaultsApply() {

LayoutRecommendationInfo layoutRecommendationInfo = new LayoutRecommendationInfo(new HashMap<>(), new HashMap<>()); // contents doesn't matter for the test
AddServiceRequest request = request(ConfigRecommendationStrategy.ONLY_STACK_DEFAULTS_APPLY);
AddServiceInfo info = ADD_SERVICE_INFO_BUILDER
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(userConfig)
Expand Down Expand Up @@ -696,6 +644,58 @@ public void removeNonStackConfigRecommendations() {
assertEquals(recommendedConfigsForStackDefaults, recommendedConfigs);
}

@Test
public void getLayoutRecommendationInfo() {
Map<String, Map<String, Set<String>>> newServices = ImmutableMap.of(
"KAFKA", ImmutableMap.of(
"KAFKA_BROKER", ImmutableSet.of("c7401")),
"SPARK2", ImmutableMap.of(
"SPARK2_JOBHISTORYSERVER", ImmutableSet.of("c7402"),
"SPARK2_CLIENT", ImmutableSet.of("c7403", "c7404")),
"OOZIE", ImmutableMap.of(
"OOZIE_SERVER", ImmutableSet.of("c7401"),
"OOZIE_CLIENT", ImmutableSet.of("c7403", "c7404")));

AddServiceRequest request = request(ConfigRecommendationStrategy.ALWAYS_APPLY);
AddServiceInfo info = addServiceInfoBuilder
.setRequest(request)
.setStack(stack)
.setConfig(Configuration.newEmpty())
.setNewServices(newServices)
.build(); // No LayoutReommendationInfo -> needs to be calculated

LayoutRecommendationInfo layoutRecommendationInfo = adapter.getLayoutRecommendationInfo(info);
layoutRecommendationInfo.getAllServiceLayouts();

assertEquals(
ImmutableMap.of(
"host_group_1", ImmutableSet.of("c7401"),
"host_group_2", ImmutableSet.of("c7402"),
"host_group_3", ImmutableSet.of("c7403", "c7404")),
layoutRecommendationInfo.getHostGroups());

assertEquals(
ImmutableMap.<String, Map<String, Set<String>>>builder()
.put("KAFKA", ImmutableMap.of(
"KAFKA_BROKER", ImmutableSet.of("c7401")))
.put("SPARK2", ImmutableMap.of(
"SPARK2_JOBHISTORYSERVER", ImmutableSet.of("c7402"),
"SPARK2_CLIENT", ImmutableSet.of("c7403", "c7404")))
.put("OOZIE", ImmutableMap.of(
"OOZIE_SERVER", ImmutableSet.of("c7401"),
"OOZIE_CLIENT", ImmutableSet.of("c7403", "c7404")))
.put("HDFS", ImmutableMap.of(
"NAMENODE", ImmutableSet.of("c7401"),
"HDFS_CLIENT", ImmutableSet.of("c7401", "c7402")))
.put("ZOOKEEPER", ImmutableMap.of(
"ZOOKEEPER_SERVER", ImmutableSet.of("c7401"),
"ZOOKEEPER_CLIENT", ImmutableSet.of("c7401", "c7402")))
.put("MAPREDUCE2", ImmutableMap.of(
"HISTORYSERVER", ImmutableSet.of("c7401")))
.build(),
layoutRecommendationInfo.getAllServiceLayouts());
}

private static AddServiceRequest request(ConfigRecommendationStrategy strategy) {
return new AddServiceRequest(null, strategy, null, null, null, null, null, null, null, null, null);
}
Expand Down

0 comments on commit cf82327

Please sign in to comment.