|
@@ -28,8 +28,21 @@ import static org.easymock.EasyMock.verify;
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import org.apache.ambari.server.actionmanager.ActionManager;
|
|
|
+import org.apache.ambari.server.controller.AmbariManagementController;
|
|
|
+import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
|
|
|
+import org.apache.ambari.server.controller.KerberosHelper;
|
|
|
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
|
|
|
import org.apache.ambari.server.orm.DBAccessor;
|
|
|
+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.stack.OsFamily;
|
|
|
+import org.easymock.Capture;
|
|
|
+import org.easymock.EasyMock;
|
|
|
+import org.easymock.EasyMockSupport;
|
|
|
import org.junit.After;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
@@ -40,6 +53,15 @@ import com.google.inject.Injector;
|
|
|
import com.google.inject.Module;
|
|
|
import com.google.inject.Provider;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.easymock.EasyMock.anyObject;
|
|
|
+import static org.easymock.EasyMock.anyString;
|
|
|
+import static org.easymock.EasyMock.capture;
|
|
|
+import static org.easymock.EasyMock.createMockBuilder;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
/**
|
|
|
* {@link UpgradeCatalog250} unit tests.
|
|
|
*/
|
|
@@ -86,4 +108,92 @@ public class UpgradeCatalog250Test {
|
|
|
verify(dbAccessor);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testExecuteDMLUpdates() throws Exception {
|
|
|
+ Method updateAmsConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateAMSConfigs");
|
|
|
+
|
|
|
+ UpgradeCatalog250 upgradeCatalog250 = createMockBuilder(UpgradeCatalog250.class)
|
|
|
+ .addMockedMethod(updateAmsConfigs)
|
|
|
+ .createMock();
|
|
|
+
|
|
|
+ upgradeCatalog250.updateAMSConfigs();
|
|
|
+ expectLastCall().once();
|
|
|
+
|
|
|
+ replay(upgradeCatalog250);
|
|
|
+
|
|
|
+ upgradeCatalog250.executeDMLUpdates();
|
|
|
+
|
|
|
+ verify(upgradeCatalog250);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testAmsEnvUpdateConfigs() throws Exception{
|
|
|
+
|
|
|
+ Map<String, String> oldPropertiesAmsEnv = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("content", "\n" +
|
|
|
+ "# AMS Collector heapsize\n" +
|
|
|
+ "export AMS_COLLECTOR_HEAPSIZE={{metrics_collector_heapsize}}\n" +
|
|
|
+ "\n" +
|
|
|
+ "# HBase normalizer enabled\n" +
|
|
|
+ "export AMS_HBASE_NORMALIZER_ENABLED={{ams_hbase_normalizer_enabled}}\n" +
|
|
|
+ "\n" +
|
|
|
+ "# HBase compaction policy enabled\n" +
|
|
|
+ "export HBASE_FIFO_COMPACTION_POLICY_ENABLED={{ams_hbase_fifo_compaction_policy_enabled}}\n" +
|
|
|
+ "\n" +
|
|
|
+ "# HBase Tables Initialization check enabled\n" +
|
|
|
+ "export AMS_HBASE_INIT_CHECK_ENABLED={{ams_hbase_init_check_enabled}}\n");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Map<String, String> newPropertiesAmsEnv = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("content", "\n" +
|
|
|
+ "# AMS Collector heapsize\n" +
|
|
|
+ "export AMS_COLLECTOR_HEAPSIZE={{metrics_collector_heapsize}}\n" +
|
|
|
+ "\n" +
|
|
|
+ "# HBase Tables Initialization check enabled\n" +
|
|
|
+ "export AMS_HBASE_INIT_CHECK_ENABLED={{ams_hbase_init_check_enabled}}\n");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ EasyMockSupport easyMockSupport = new EasyMockSupport();
|
|
|
+
|
|
|
+ Clusters clusters = easyMockSupport.createNiceMock(Clusters.class);
|
|
|
+ final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class);
|
|
|
+ Config mockAmsEnv = easyMockSupport.createNiceMock(Config.class);
|
|
|
+
|
|
|
+ expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
|
|
|
+ put("normal", cluster);
|
|
|
+ }}).once();
|
|
|
+ expect(cluster.getDesiredConfigByType("ams-env")).andReturn(mockAmsEnv).atLeastOnce();
|
|
|
+ expect(mockAmsEnv.getProperties()).andReturn(oldPropertiesAmsEnv).anyTimes();
|
|
|
+
|
|
|
+ Injector injector = easyMockSupport.createNiceMock(Injector.class);
|
|
|
+ expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes();
|
|
|
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes();
|
|
|
+ expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes();
|
|
|
+
|
|
|
+ replay(injector, clusters, mockAmsEnv, cluster);
|
|
|
+
|
|
|
+ AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
|
|
|
+ .addMockedMethod("createConfiguration")
|
|
|
+ .addMockedMethod("getClusters", new Class[] { })
|
|
|
+ .addMockedMethod("createConfig")
|
|
|
+ .withConstructor(createNiceMock(ActionManager.class), clusters, injector)
|
|
|
+ .createNiceMock();
|
|
|
+
|
|
|
+ Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
|
|
|
+ Capture<Map> propertiesCapture = EasyMock.newCapture();
|
|
|
+
|
|
|
+ expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
|
|
|
+ expect(controller.getClusters()).andReturn(clusters).anyTimes();
|
|
|
+ expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
|
|
|
+ anyObject(Map.class))).andReturn(createNiceMock(Config.class)).once();
|
|
|
+
|
|
|
+ replay(controller, injector2);
|
|
|
+ new UpgradeCatalog250(injector2).updateAMSConfigs();
|
|
|
+ easyMockSupport.verifyAll();
|
|
|
+
|
|
|
+ Map<String, String> updatedProperties = propertiesCapture.getValue();
|
|
|
+ assertTrue(Maps.difference(newPropertiesAmsEnv, updatedProperties).areEqual());
|
|
|
+ }
|
|
|
}
|