|
@@ -17,12 +17,14 @@
|
|
|
*/
|
|
|
package org.apache.ambari.server.orm.dao;
|
|
|
|
|
|
+import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.apache.ambari.server.AmbariException;
|
|
|
+import org.apache.ambari.server.H2DatabaseCleaner;
|
|
|
import org.apache.ambari.server.api.services.AmbariMetaInfo;
|
|
|
import org.apache.ambari.server.orm.GuiceJpaInitializer;
|
|
|
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
|
|
@@ -47,7 +49,6 @@ import org.junit.Test;
|
|
|
|
|
|
import com.google.inject.Guice;
|
|
|
import com.google.inject.Injector;
|
|
|
-import com.google.inject.persist.PersistService;
|
|
|
|
|
|
public class ServiceConfigDAOTest {
|
|
|
private static final StackId HDP_01 = new StackId("HDP", "0.1");
|
|
@@ -78,8 +79,8 @@ public class ServiceConfigDAOTest {
|
|
|
}
|
|
|
|
|
|
@After
|
|
|
- public void teardown() throws AmbariException {
|
|
|
- injector.getInstance(PersistService.class).stop();
|
|
|
+ public void teardown() throws AmbariException, SQLException {
|
|
|
+ H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
|
|
|
}
|
|
|
|
|
|
private ServiceConfigEntity createServiceConfig(String serviceName,
|
|
@@ -156,9 +157,11 @@ public class ServiceConfigDAOTest {
|
|
|
ServiceConfigEntity serviceConfigEntity =
|
|
|
createServiceConfig("HDFS", "admin", 1L, 1L, 1111L, null);
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
Assert.assertNotNull(serviceConfigEntity);
|
|
|
Assert.assertEquals("c1", serviceConfigEntity.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), serviceConfigEntity.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, serviceConfigEntity.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals("HDFS", serviceConfigEntity.getServiceName());
|
|
|
Assert.assertEquals(Long.valueOf(1111L), serviceConfigEntity.getCreateTimestamp());
|
|
@@ -175,9 +178,11 @@ public class ServiceConfigDAOTest {
|
|
|
|
|
|
ServiceConfigEntity serviceConfigEntity = serviceConfigDAO.find(sce.getServiceConfigId());
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
Assert.assertNotNull(serviceConfigEntity);
|
|
|
Assert.assertEquals("c1", serviceConfigEntity.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), serviceConfigEntity.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, serviceConfigEntity.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals("HDFS", serviceConfigEntity.getServiceName());
|
|
|
Assert.assertEquals(Long.valueOf(1111L), serviceConfigEntity.getCreateTimestamp());
|
|
@@ -195,9 +200,11 @@ public class ServiceConfigDAOTest {
|
|
|
ServiceConfigEntity serviceConfigEntity =
|
|
|
serviceConfigDAO.findByServiceAndVersion("HDFS", 1L);
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
Assert.assertNotNull(serviceConfigEntity);
|
|
|
Assert.assertEquals("c1", serviceConfigEntity.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), serviceConfigEntity.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, serviceConfigEntity.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals("HDFS", serviceConfigEntity.getServiceName());
|
|
|
Assert.assertEquals(Long.valueOf(1111L), serviceConfigEntity.getCreateTimestamp());
|
|
@@ -235,10 +242,12 @@ public class ServiceConfigDAOTest {
|
|
|
Assert.assertNotNull(serviceConfigEntities);
|
|
|
Assert.assertEquals(2, serviceConfigEntities.size());
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
for (ServiceConfigEntity sce: serviceConfigEntities) {
|
|
|
if ("HDFS".equals(sce.getServiceName())) {
|
|
|
Assert.assertEquals("c1", sce.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), sce.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, sce.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals(Long.valueOf(2222L), sce.getCreateTimestamp());
|
|
|
Assert.assertEquals(Long.valueOf(2), sce.getVersion());
|
|
@@ -247,7 +256,7 @@ public class ServiceConfigDAOTest {
|
|
|
}
|
|
|
if ("YARN".equals(sce.getServiceName())) {
|
|
|
Assert.assertEquals("c1", sce.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), sce.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, sce.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals(Long.valueOf(3333L), sce.getCreateTimestamp());
|
|
|
Assert.assertEquals(Long.valueOf(1), sce.getVersion());
|
|
@@ -289,12 +298,14 @@ public class ServiceConfigDAOTest {
|
|
|
createServiceConfig("HDFS", "admin", 2L, 2L, 2222L, null);
|
|
|
createServiceConfig("YARN", "admin", 1L, 3L, 3333L, null);
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
ServiceConfigEntity serviceConfigEntity =
|
|
|
- serviceConfigDAO.getLastServiceConfig(1L, "HDFS");
|
|
|
+ serviceConfigDAO.getLastServiceConfig(clusterId, "HDFS");
|
|
|
|
|
|
Assert.assertNotNull(serviceConfigEntity);
|
|
|
Assert.assertEquals("c1", serviceConfigEntity.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), serviceConfigEntity.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, serviceConfigEntity.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals("HDFS", serviceConfigEntity.getServiceName());
|
|
|
Assert.assertEquals(Long.valueOf(2222L), serviceConfigEntity.getCreateTimestamp());
|
|
@@ -310,8 +321,10 @@ public class ServiceConfigDAOTest {
|
|
|
createServiceConfig("HDFS", "admin", 2L, 2L, 2222L, null);
|
|
|
createServiceConfig("YARN", "admin", 1L, 3L, 3333L, null);
|
|
|
|
|
|
+ Long clusterId = clusterDAO.findByName("c1").getClusterId();
|
|
|
+
|
|
|
List<ServiceConfigEntity> serviceConfigEntities =
|
|
|
- serviceConfigDAO.getServiceConfigs(clusterDAO.findByName("c1").getClusterId());
|
|
|
+ serviceConfigDAO.getServiceConfigs(clusterId);
|
|
|
|
|
|
Assert.assertNotNull(serviceConfigEntities);
|
|
|
Assert.assertEquals(3, serviceConfigEntities.size());
|
|
@@ -319,21 +332,21 @@ public class ServiceConfigDAOTest {
|
|
|
for (ServiceConfigEntity sce: serviceConfigEntities) {
|
|
|
if ("HDFS".equals(sce.getServiceName()) && (sce.getVersion() == 1)) {
|
|
|
Assert.assertEquals("c1", sce.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), sce.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, sce.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals(Long.valueOf(1111L), sce.getCreateTimestamp());
|
|
|
Assert.assertTrue(sce.getClusterConfigEntities().isEmpty());
|
|
|
Assert.assertNotNull(sce.getServiceConfigId());
|
|
|
} else if ("HDFS".equals(sce.getServiceName()) && (sce.getVersion() == 2)) {
|
|
|
Assert.assertEquals("c1", sce.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), sce.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, sce.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals(Long.valueOf(2222L), sce.getCreateTimestamp());
|
|
|
Assert.assertTrue(sce.getClusterConfigEntities().isEmpty());
|
|
|
Assert.assertNotNull(sce.getServiceConfigId());
|
|
|
} else if ("YARN".equals(sce.getServiceName())) {
|
|
|
Assert.assertEquals("c1", sce.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), sce.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, sce.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals(Long.valueOf(3333L), sce.getCreateTimestamp());
|
|
|
Assert.assertEquals(Long.valueOf(1), sce.getVersion());
|
|
@@ -434,6 +447,7 @@ public class ServiceConfigDAOTest {
|
|
|
public void testGetClusterConfigMappingByStackCG() throws Exception{
|
|
|
initClusterEntitiesWithConfigGroups();
|
|
|
ClusterEntity clusterEntity = clusterDAO.findByName("c1");
|
|
|
+ Long clusterId = clusterEntity.getClusterId();
|
|
|
|
|
|
List<ConfigGroupEntity> configGroupEntities = configGroupDAO.findAllByTag("OOZIE");
|
|
|
|
|
@@ -441,7 +455,7 @@ public class ServiceConfigDAOTest {
|
|
|
ConfigGroupEntity configGroupEntity = configGroupEntities.get(0);
|
|
|
Assert.assertNotNull(configGroupEntity);
|
|
|
Assert.assertEquals("c1", configGroupEntity.getClusterEntity().getClusterName());
|
|
|
- Assert.assertEquals(Long.valueOf(1), configGroupEntity.getClusterEntity()
|
|
|
+ Assert.assertEquals(clusterId, configGroupEntity.getClusterEntity()
|
|
|
.getClusterId());
|
|
|
Assert.assertEquals("oozie_server", configGroupEntity.getGroupName());
|
|
|
Assert.assertEquals("OOZIE", configGroupEntity.getTag());
|
|
@@ -545,6 +559,7 @@ public class ServiceConfigDAOTest {
|
|
|
String oozieSite = "oozie-site";
|
|
|
|
|
|
for (int i = 1; i < 6; i++){
|
|
|
+ Thread.sleep(1);
|
|
|
ClusterConfigEntity entity = new ClusterConfigEntity();
|
|
|
entity.setClusterEntity(clusterEntity);
|
|
|
entity.setClusterId(clusterEntity.getClusterId());
|
|
@@ -591,6 +606,7 @@ public class ServiceConfigDAOTest {
|
|
|
entities.add(e2);
|
|
|
clusterDAO.merge(clusterEntity);
|
|
|
|
|
|
+ Thread.sleep(1);
|
|
|
ClusterConfigMappingEntity e3 = new ClusterConfigMappingEntity();
|
|
|
e3.setClusterEntity(clusterEntity);
|
|
|
e3.setClusterId(clusterEntity.getClusterId());
|
|
@@ -622,6 +638,7 @@ public class ServiceConfigDAOTest {
|
|
|
|
|
|
int count = 3;
|
|
|
for (int i = 1; i < count; i++){
|
|
|
+ Thread.sleep(1);
|
|
|
ClusterConfigEntity entity = new ClusterConfigEntity();
|
|
|
entity.setClusterEntity(clusterEntity);
|
|
|
entity.setClusterId(clusterEntity.getClusterId());
|
|
@@ -642,6 +659,7 @@ public class ServiceConfigDAOTest {
|
|
|
clusterEntity.setConfigMappingEntities(entities);
|
|
|
}
|
|
|
|
|
|
+ Thread.sleep(1);
|
|
|
ClusterConfigMappingEntity e1 = new ClusterConfigMappingEntity();
|
|
|
e1.setClusterEntity(clusterEntity);
|
|
|
e1.setClusterId(clusterEntity.getClusterId());
|
|
@@ -653,6 +671,7 @@ public class ServiceConfigDAOTest {
|
|
|
entities.add(e1);
|
|
|
clusterDAO.merge(clusterEntity);
|
|
|
|
|
|
+ Thread.sleep(1);
|
|
|
ClusterConfigMappingEntity e2 = new ClusterConfigMappingEntity();
|
|
|
e2.setClusterEntity(clusterEntity);
|
|
|
e2.setClusterId(clusterEntity.getClusterId());
|
|
@@ -690,12 +709,14 @@ public class ServiceConfigDAOTest {
|
|
|
configEntity.setAttributes("someAttributes");
|
|
|
configEntity.setStack(stackEntityHDP01);
|
|
|
|
|
|
+ Thread.sleep(1);
|
|
|
List<ClusterConfigEntity> configEntities = new
|
|
|
ArrayList<ClusterConfigEntity>();
|
|
|
configEntities.add(configEntity);
|
|
|
|
|
|
configGroupDAO.create(configGroupEntity);
|
|
|
|
|
|
+ Thread.sleep(1);
|
|
|
if (configEntities != null && !configEntities.isEmpty()) {
|
|
|
List<ConfigGroupConfigMappingEntity> configMappingEntities = new
|
|
|
ArrayList<ConfigGroupConfigMappingEntity>();
|
|
@@ -722,4 +743,4 @@ public class ServiceConfigDAOTest {
|
|
|
configGroupDAO.merge(configGroupEntity);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|