Repository: ambari Updated Branches: refs/heads/branch-2.5 4a565d347 -> 704170e4e
http://git-wip-us.apache.org/repos/asf/ambari/blob/704170e4/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java index 596f381..5c8d174 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java @@ -384,7 +384,7 @@ public class HostTest { clusters.mapHostToCluster("h1", "c1"); ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config config = configFactory.createNew(c1, "global", + Config config = configFactory.createNew(c1, "global", "v1", new HashMap<String,String>() {{ put("a", "b"); put("x", "y"); }}, new HashMap<String, Map<String,String>>()); try { @@ -396,16 +396,14 @@ public class HostTest { } - config.setTag("v1"); host.addDesiredConfig(c1.getClusterId(), true, "_test", config); Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId()); Assert.assertTrue("Expect desired config to contain global", map.containsKey("global")); Assert.assertEquals("Expect global user to be '_test'", "_test", map.get("global").getUser()); - config = configFactory.createNew(c1, "global", + config = configFactory.createNew(c1, "global", "v2", new HashMap<String,String>() {{ put("c", "d"); }}, new HashMap<String, Map<String,String>>()); - config.setTag("v2"); host.addDesiredConfig(c1.getClusterId(), true, "_test1", config); map = host.getDesiredConfigs(c1.getClusterId()); http://git-wip-us.apache.org/repos/asf/ambari/blob/704170e4/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java index 77e5142..5987af3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java @@ -221,11 +221,8 @@ public class ServiceComponentHostTest { Cluster c = clusters.getCluster(clusterName); if (c.getConfig("time", String.valueOf(timestamp)) == null) { - Config config = configFactory.createNew (c, "time", + Config config = configFactory.createNew (c, "time", String.valueOf(timestamp), new HashMap<String, String>(), new HashMap<String, Map<String,String>>()); - config.setTag(String.valueOf(timestamp)); - c.addConfig(config); - config.persist(); } switch (eventType) { @@ -564,7 +561,6 @@ public class ServiceComponentHostTest { final ConfigGroup configGroup = configGroupFactory.createNew(cluster, "cg1", "t1", "", new HashMap<String, Config>(), new HashMap<Long, Host>()); - configGroup.persist(); cluster.addConfigGroup(configGroup); Map<String, Map<String,String>> actual = @@ -815,17 +811,14 @@ public class ServiceComponentHostTest { final Host host = clusters.getHostsForCluster(clusterName).get(hostName); Assert.assertNotNull(host); - final Config c = configFactory.createNew(cluster, "hdfs-site", + final Config c = configFactory.createNew(cluster, "hdfs-site", "version3", new HashMap<String, String>() {{ put("dfs.journalnode.http-address", "http://goo"); }}, new HashMap<String, Map<String,String>>()); - c.setTag("version3"); - c.persist(); - cluster.addConfig(c); + host.addDesiredConfig(cluster.getClusterId(), true, "user", c); ConfigGroup configGroup = configGroupFactory.createNew(cluster, "g1", "t1", "", new HashMap<String, Config>() {{ put("hdfs-site", c); }}, new HashMap<Long, Host>() {{ put(hostEntity.getHostId(), host); }}); - configGroup.persist(); cluster.addConfigGroup(configGroup); // HDP-x/HDFS/hdfs-site updated host to changed property @@ -876,16 +869,12 @@ public class ServiceComponentHostTest { sch1.updateActualConfigs(actual); - final Config c1 = configFactory.createNew(cluster, "core-site", + final Config c1 = configFactory.createNew(cluster, "core-site", "version2", new HashMap<String, String>() {{ put("fs.trash.interval", "400"); }}, new HashMap<String, Map<String,String>>()); - c1.setTag("version2"); - c1.persist(); - cluster.addConfig(c1); configGroup = configGroupFactory.createNew(cluster, "g2", "t2", "", new HashMap<String, Config>() {{ put("core-site", c1); }}, new HashMap<Long, Host>() {{ put(hostEntity.getHostId(), host); }}); - configGroup.persist(); cluster.addConfigGroup(configGroup); Assert.assertTrue(sch1.convertToResponse(null).isStaleConfig()); @@ -1039,10 +1028,7 @@ public class ServiceComponentHostTest { * @param values the values for the config */ private void makeConfig(Cluster cluster, String type, String tag, Map<String, String> values, Map<String, Map<String, String>> attributes) { - Config config = configFactory.createNew(cluster, type, values, attributes); - config.setTag(tag); - config.persist(); - cluster.addConfig(config); + Config config = configFactory.createNew(cluster, type, tag, values, attributes); cluster.addDesiredConfig("user", Collections.singleton(config)); } http://git-wip-us.apache.org/repos/asf/ambari/blob/704170e4/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java index 82526e7..fac5185 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java @@ -59,6 +59,7 @@ import org.apache.ambari.server.controller.spi.Resource; 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.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; @@ -66,13 +67,14 @@ import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.easymock.Capture; +import org.easymock.EasyMock; import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableList; /** * AmbariContext unit tests @@ -110,6 +112,7 @@ public class AmbariContextTest { private static final ConfigGroup configGroup2 = createMock(ConfigGroup.class); private static final Host host1 = createNiceMock(Host.class); private static final Host host2 = createNiceMock(Host.class); + private static final ConfigFactory configFactory = createNiceMock(ConfigFactory.class); private static final Collection<String> blueprintServices = new HashSet<String>(); private static final Map<String, Service> clusterServices = new HashMap<String, Service>(); @@ -164,6 +167,9 @@ public class AmbariContextTest { type1Props.put("prop3", "val3"); group1Configuration = new Configuration(group1Properties, null, bpConfiguration); + Map<String, String> group1ResolvedProperties = new HashMap<String, String>(bpType1Props); + group1ResolvedProperties.putAll(type1Props); + // config type -> service mapping Map<String, String> configTypeServiceMapping = new HashMap<String, String>(); configTypeServiceMapping.put("type1", "service1"); @@ -172,6 +178,28 @@ public class AmbariContextTest { configGroups.put(1L, configGroup1); configGroups.put(2L, configGroup2); + // config factory mock + Config type1Group1 = createNiceMock(Config.class); + expect(type1Group1.getType()).andReturn("type1").anyTimes(); + expect(type1Group1.getTag()).andReturn("group1").anyTimes(); + expect(type1Group1.getProperties()).andReturn(group1ResolvedProperties).anyTimes(); + expect(configFactory.createReadOnly(EasyMock.eq("type1"), EasyMock.eq("group1"), + EasyMock.<Map<String, String>> anyObject(), + EasyMock.<Map<String, Map<String, String>>> anyObject())).andReturn(type1Group1).anyTimes(); + replay(type1Group1); + + Config type1Service1 = createNiceMock(Config.class); + expect(type1Service1.getType()).andReturn("type1").anyTimes(); + expect(type1Service1.getTag()).andReturn("service1").anyTimes(); + expect(type1Service1.getProperties()).andReturn(type1Props).anyTimes(); + expect(configFactory.createReadOnly(EasyMock.eq("type1"), EasyMock.eq("service1"), + EasyMock.<Map<String, String>> anyObject(), + EasyMock.<Map<String, Map<String, String>>> anyObject())).andReturn( + type1Service1).anyTimes(); + replay(type1Service1); + + context.configFactory = configFactory; + blueprintServices.add("service1"); blueprintServices.add("service2"); @@ -222,17 +250,17 @@ public class AmbariContextTest { public void tearDown() throws Exception { verify(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); reset(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); } private void replayAll() { replay(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); } @Test @@ -330,6 +358,7 @@ public class AmbariContextTest { 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(); + // replay all mocks replayAll(); @@ -416,7 +445,6 @@ public class AmbariContextTest { expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(2L, host2)).once(); configGroup1.addHost(host1); - configGroup1.persistHostMapping(); // replay all mocks replayAll(); http://git-wip-us.apache.org/repos/asf/ambari/blob/704170e4/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java index f9dd5d1..3bb6c0a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java @@ -49,6 +49,8 @@ import org.apache.ambari.server.orm.entities.StackEntity; 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.ConfigFactory; +import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.stack.OsFamily; import org.apache.ambari.server.utils.CollectionPresentationUtils; @@ -62,6 +64,7 @@ import com.google.gson.JsonPrimitive; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.assistedinject.FactoryModuleBuilder; import junit.framework.Assert; @@ -212,16 +215,12 @@ public class HostUpdateHelperTest { Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); Cluster mockCluster = easyMockSupport.createNiceMock(Cluster.class); ClusterEntity mockClusterEntity1 = easyMockSupport.createNiceMock(ClusterEntity.class); - ClusterEntity mockClusterEntity2 = easyMockSupport.createNiceMock(ClusterEntity.class); ClusterConfigEntity mockClusterConfigEntity1 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); ClusterConfigEntity mockClusterConfigEntity2 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); - ClusterConfigEntity mockClusterConfigEntity3 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); - ClusterConfigEntity mockClusterConfigEntity4 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); StackEntity mockStackEntity = easyMockSupport.createNiceMock(StackEntity.class); Map<String, Map<String, String>> clusterHostsToChange = new HashMap<>(); Map<String, String> hosts = new HashMap<>(); List<ClusterConfigEntity> clusterConfigEntities1 = new ArrayList<>(); - List<ClusterConfigEntity> clusterConfigEntities2 = new ArrayList<>(); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override @@ -231,6 +230,8 @@ public class HostUpdateHelperTest { bind(EntityManager.class).toInstance(entityManager); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(ClusterDAO.class).toInstance(mockClusterDAO); + + install(new FactoryModuleBuilder().implement(Config.class, ConfigImpl.class).build(ConfigFactory.class)); } }); @@ -242,49 +243,42 @@ public class HostUpdateHelperTest { clusterConfigEntities1.add(mockClusterConfigEntity1); clusterConfigEntities1.add(mockClusterConfigEntity2); - clusterConfigEntities2.add(mockClusterConfigEntity3); - clusterConfigEntities2.add(mockClusterConfigEntity4); - clusterHostsToChange.put("cl1", hosts); - expect(mockClusterDAO.findByName("cl1")).andReturn(mockClusterEntity1).once(); - expect(mockClusterDAO.findById(1L)).andReturn(mockClusterEntity2).atLeastOnce(); + expect(mockClusterDAO.findByName("cl1")).andReturn(mockClusterEntity1).atLeastOnce(); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getCluster("cl1")).andReturn(mockCluster).once(); - expect(mockCluster.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockCluster.getClusterId()).andReturn(1L).anyTimes(); expect(mockClusterEntity1.getClusterConfigEntities()).andReturn(clusterConfigEntities1).atLeastOnce(); - expect(mockClusterEntity2.getClusterConfigEntities()).andReturn(clusterConfigEntities2).atLeastOnce(); - expect(mockClusterConfigEntity1.getStack()).andReturn(mockStackEntity).once(); + expect(mockClusterConfigEntity1.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity1.getConfigId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity1.getStack()).andReturn(mockStackEntity).atLeastOnce(); expect(mockClusterConfigEntity1.getData()).andReturn("{\"testProperty1\" : \"testValue_host1\", " + "\"testProperty2\" : \"testValue_host5\", \"testProperty3\" : \"testValue_host11\", " + "\"testProperty4\" : \"testValue_host55\"}").atLeastOnce(); expect(mockClusterConfigEntity1.getTag()).andReturn("testTag1").atLeastOnce(); expect(mockClusterConfigEntity1.getType()).andReturn("testType1").atLeastOnce(); expect(mockClusterConfigEntity1.getVersion()).andReturn(1L).atLeastOnce(); + expect(mockClusterDAO.findConfig(1L)).andReturn(mockClusterConfigEntity1).atLeastOnce(); - expect(mockClusterConfigEntity2.getStack()).andReturn(mockStackEntity).once(); + expect(mockClusterConfigEntity2.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity2.getConfigId()).andReturn(2L).anyTimes(); + expect(mockClusterConfigEntity2.getStack()).andReturn(mockStackEntity).atLeastOnce(); expect(mockClusterConfigEntity2.getData()).andReturn("{\"testProperty5\" : \"test_host1_test_host5_test_host11_test_host55\"}").atLeastOnce(); expect(mockClusterConfigEntity2.getTag()).andReturn("testTag2").atLeastOnce(); expect(mockClusterConfigEntity2.getType()).andReturn("testType2").atLeastOnce(); expect(mockClusterConfigEntity2.getVersion()).andReturn(2L).atLeastOnce(); - - expect(mockClusterConfigEntity3.getTag()).andReturn("testTag1").atLeastOnce(); - expect(mockClusterConfigEntity3.getType()).andReturn("testType1").atLeastOnce(); - expect(mockClusterConfigEntity3.getVersion()).andReturn(1L).atLeastOnce(); - - expect(mockClusterConfigEntity4.getTag()).andReturn("testTag2").atLeastOnce(); - expect(mockClusterConfigEntity4.getType()).andReturn("testType2").atLeastOnce(); - expect(mockClusterConfigEntity4.getVersion()).andReturn(2L).atLeastOnce(); + expect(mockClusterDAO.findConfig(2L)).andReturn(mockClusterConfigEntity2).atLeastOnce(); Capture<String> dataCapture = EasyMock.newCapture(); - mockClusterConfigEntity3.setData(EasyMock.capture(dataCapture)); + mockClusterConfigEntity1.setData(EasyMock.capture(dataCapture)); expectLastCall(); - mockClusterConfigEntity4.setData("{\"testProperty5\":\"test_host5_test_host1_test_host55_test_host11\"}"); + mockClusterConfigEntity2.setData("{\"testProperty5\":\"test_host5_test_host1_test_host55_test_host11\"}"); expectLastCall(); HostUpdateHelper hostUpdateHelper = new HostUpdateHelper(null, null, mockInjector); http://git-wip-us.apache.org/repos/asf/ambari/blob/704170e4/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java index 29f40fb..5c77831 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java @@ -65,6 +65,9 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService; import org.apache.ambari.server.stack.StackManagerFactory; 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.ConfigFactory; +import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostComponentAdminState; import org.apache.ambari.server.state.Service; @@ -126,6 +129,7 @@ public class StageUtilsTest extends EasyMockSupport { bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class)); install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class)); + install(new FactoryModuleBuilder().implement(Config.class, ConfigImpl.class).build(ConfigFactory.class)); } });