eubnara commented on code in PR #4262:
URL: https://github.com/apache/ambari/pull/4262#discussion_r4547024623


##########
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java:
##########
@@ -262,6 +262,79 @@ public void 
testServiceMetadataCredentialsAreResolvedForEachClusterService() thr
         repositoryVersionB, serviceA, serviceB, serviceInfo);
   }
 
+  @Test
+  public void testAddedHostComponentsRefreshAgentConfigsOfTheirHosts() throws 
Exception {
+    // Config pushes skip hosts without a component of the owning service, so 
a host that gains
+    // components (e.g. a new service whose configs were saved first) must be 
refreshed here.
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = 
EasyMock.newCapture();
+    constructorInit(injector, controllerCapture, 
createNiceMock(KerberosHelper.class));
+
+    ConfigHelper localConfigHelper = createMock(ConfigHelper.class);
+    Cluster cluster = createMock(Cluster.class);
+    Host host1 = createMock(Host.class);
+    Host host2 = createMock(Host.class);
+    Capture<List<Long>> pushedHostIds = EasyMock.newCapture();
+
+    expect(clusters.getHost("host1")).andReturn(host1).times(2);
+    expect(clusters.getHost("host2")).andReturn(host2);
+    expect(host1.getHostId()).andReturn(1L).times(2);
+    expect(host2.getHostId()).andReturn(2L);
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    localConfigHelper.updateAgentConfigs(eq(cluster), capture(pushedHostIds));
+    expectLastCall().once();
+
+    replay(injector, clusters, cluster, host1, host2, localConfigHelper);
+
+    AmbariManagementControllerImpl controller = new 
AmbariManagementControllerImpl(null, clusters, injector);
+    Field configHelperField = 
AmbariManagementControllerImpl.class.getDeclaredField("configHelper");
+    configHelperField.setAccessible(true);
+    configHelperField.set(controller, localConfigHelper);
+
+    controller.updateAgentConfigsForAddedComponents(new 
HashSet<>(Arrays.asList(
+        new ServiceComponentHostRequest("cluster1", "RANGER", "RANGER_ADMIN", 
"host1", null),
+        new ServiceComponentHostRequest("cluster1", "RANGER", 
"RANGER_USERSYNC", "host1", null),
+        new ServiceComponentHostRequest("cluster1", "RANGER", 
"RANGER_TAGSYNC", "host2", null))));
+
+    // One push per cluster, each host that received a component exactly once.
+    assertEquals(2, pushedHostIds.getValue().size());
+    assertEquals(new HashSet<>(Arrays.asList(1L, 2L)), new 
HashSet<>(pushedHostIds.getValue()));
+    verify(injector, clusters, cluster, host1, host2, localConfigHelper);
+  }
+
+  @Test
+  public void testAddedHostComponentsFailWhenAgentConfigsCannotBeRefreshed() 
throws Exception {
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = 
EasyMock.newCapture();
+    constructorInit(injector, controllerCapture, 
createNiceMock(KerberosHelper.class));
+
+    ConfigHelper localConfigHelper = createMock(ConfigHelper.class);
+    Cluster cluster = createMock(Cluster.class);
+    Host host1 = createMock(Host.class);
+
+    expect(clusters.getHost("host1")).andReturn(host1);
+    expect(host1.getHostId()).andReturn(1L);
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    localConfigHelper.updateAgentConfigs(eq(cluster), 
eq(Collections.singletonList(1L)));
+    expectLastCall().andThrow(new AmbariException("Configurations for cluster 
2 are unavailable for host 1"));

Review Comment:
   The test uses 'cluster1'. Is it a typo?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to