ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/2] ambari git commit: Revert "AMBARI-14249. Failing unit tests / Entity removal using the entity manager instead of named queries. (Laszlo Puskas via swagle)"
Date Tue, 15 Dec 2015 19:02:25 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 4eee909b1 -> e5ce144a0


Revert "AMBARI-14249. Failing unit tests / Entity removal using the entity manager instead
of named queries. (Laszlo Puskas via swagle)"

This reverts commit 893955a598018e48e5745d02faa32b0fe440874c.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bb4fb9ed
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bb4fb9ed
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bb4fb9ed

Branch: refs/heads/branch-2.2
Commit: bb4fb9ed6e03ca13b1b55102e8585cba666d3acf
Parents: 4eee909
Author: Dmytro Sen <dsen@apache.org>
Authored: Tue Dec 15 20:58:31 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Tue Dec 15 20:58:31 2015 +0200

----------------------------------------------------------------------
 .../ambari/server/orm/dao/AlertDispatchDAO.java     | 11 ++++-------
 .../org/apache/ambari/server/orm/dao/AlertsDAO.java | 16 +++++++---------
 .../server/orm/entities/AlertHistoryEntity.java     |  2 --
 .../server/orm/entities/AlertNoticeEntity.java      |  1 -
 .../server/orm/dao/AlertDefinitionDAOTest.java      |  3 +--
 .../ambari/server/orm/dao/AlertDispatchDAOTest.java | 11 +----------
 .../apache/ambari/server/orm/dao/AlertsDAOTest.java | 12 ------------
 .../ambari/server/orm/dao/RequestDAOTest.java       |  3 ---
 8 files changed, 13 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
index d73c70e..1f1aa45 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
@@ -684,15 +684,12 @@ public class AlertDispatchDAO {
   @Transactional
   public void removeNoticeByDefinitionId(long definitionId) {
     EntityManager entityManager = entityManagerProvider.get();
-
     TypedQuery<AlertNoticeEntity> currentQuery = entityManager.createNamedQuery(
-        "AlertNoticeEntity.findByDefinitionId", AlertNoticeEntity.class);
-    currentQuery.setParameter("definitionId", definitionId);
-
-    for (AlertNoticeEntity alertNoticeEntity : currentQuery.getResultList()) {
-      entityManager.remove(alertNoticeEntity);
-    }
+        "AlertNoticeEntity.removeByDefinitionId", AlertNoticeEntity.class);
 
+    currentQuery.setParameter("definitionId", definitionId);
+    currentQuery.executeUpdate();
+    entityManager.clear();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
index 1c7d0c1..145f841 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
@@ -736,20 +736,18 @@ public class AlertsDAO {
   public void removeByDefinitionId(long definitionId) {
     EntityManager entityManager = m_entityManagerProvider.get();
     TypedQuery<AlertCurrentEntity> currentQuery = entityManager.createNamedQuery(
-        "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class);
-    currentQuery.setParameter("definitionId", definitionId);
+        "AlertCurrentEntity.removeByDefinitionId", AlertCurrentEntity.class);
 
-    for (AlertCurrentEntity alertCurrentEntity : currentQuery.getResultList()) {
-      entityManager.remove(alertCurrentEntity);
-    }
+    currentQuery.setParameter("definitionId", definitionId);
+    currentQuery.executeUpdate();
 
     TypedQuery<AlertHistoryEntity> historyQuery = entityManager.createNamedQuery(
-        "AlertHistoryEntity.findByDefinitionId", AlertHistoryEntity.class);
+        "AlertHistoryEntity.removeByDefinitionId", AlertHistoryEntity.class);
+
     historyQuery.setParameter("definitionId", definitionId);
+    historyQuery.executeUpdate();
 
-    for (AlertHistoryEntity alertHistoryEntity : historyQuery.getResultList()) {
-      entityManager.remove(alertHistoryEntity);
-    }
+    entityManager.clear();
 
     // if caching is enabled, invalidate the cache to force the latest values
     // back from the DB

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
index 6963eeb..9091398 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
@@ -51,8 +51,6 @@ import org.apache.ambari.server.state.AlertState;
     @NamedQuery(name = "AlertHistoryEntity.findAllInClusterBetweenDates", query = "SELECT
alertHistory FROM AlertHistoryEntity alertHistory WHERE alertHistory.clusterId = :clusterId
AND alertHistory.alertTimestamp BETWEEN :startDate AND :endDate"),
     @NamedQuery(name = "AlertHistoryEntity.findAllInClusterBeforeDate", query = "SELECT alertHistory
FROM AlertHistoryEntity alertHistory WHERE alertHistory.clusterId = :clusterId AND alertHistory.alertTimestamp
<= :beforeDate"),
     @NamedQuery(name = "AlertHistoryEntity.findAllInClusterAfterDate", query = "SELECT alertHistory
FROM AlertHistoryEntity alertHistory WHERE alertHistory.clusterId = :clusterId AND alertHistory.alertTimestamp
>= :afterDate"),
-    @NamedQuery(name = "AlertHistoryEntity.findByDefinitionId", query = "SELECT alertHistory
FROM AlertHistoryEntity " +
-        "alertHistory WHERE alertHistory.alertDefinition.definitionId = :definitionId"),
     @NamedQuery(name = "AlertHistoryEntity.removeByDefinitionId", query = "DELETE FROM AlertHistoryEntity
alertHistory WHERE alertHistory.alertDefinition.definitionId = :definitionId") })
 public class AlertHistoryEntity {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertNoticeEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertNoticeEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertNoticeEntity.java
index 777321e..c2f61b3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertNoticeEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertNoticeEntity.java
@@ -49,7 +49,6 @@ import org.apache.ambari.server.state.NotificationState;
     @NamedQuery(name = "AlertNoticeEntity.findAll", query = "SELECT notice FROM AlertNoticeEntity
notice"),
     @NamedQuery(name = "AlertNoticeEntity.findByState", query = "SELECT notice FROM AlertNoticeEntity
notice WHERE notice.notifyState = :notifyState"),
     @NamedQuery(name = "AlertNoticeEntity.findByUuid", query = "SELECT notice FROM AlertNoticeEntity
notice WHERE notice.uuid = :uuid"),
-    @NamedQuery(name = "AlertNoticeEntity.findByDefinitionId", query = "SELECT notice FROM
AlertNoticeEntity notice WHERE notice.alertHistory.alertDefinition.definitionId = :definitionId"),
     @NamedQuery(name = "AlertNoticeEntity.removeByDefinitionId", query = "DELETE FROM AlertNoticeEntity
notice WHERE notice.alertHistory.alertDefinition.definitionId = :definitionId") })
 public class AlertNoticeEntity {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
index c7f1de9..d0ad386 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
@@ -381,8 +381,7 @@ public class AlertDefinitionDAOTest {
     ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
     ClusterEntity clusterEntity = clusterDAO.findById(clusterId);
     clusterDAO.refresh(clusterEntity);
-    injector.getInstance(UnitOfWork.class).end();
-    injector.getInstance(UnitOfWork.class).begin();
+
     Clusters clusters = injector.getInstance(Clusters.class);
     Cluster cluster = clusters.getClusterById(clusterId);
     cluster.delete();

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
index f6b30ed..9b269b4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
@@ -513,8 +513,6 @@ public class AlertDispatchDAOTest {
     target = m_dao.findTargetById(target.getTargetId());
     assertNull(target);
 
-    m_dao.refresh(group);
-
     group = m_dao.findGroupById(group.getGroupId());
     assertNotNull(group);
 
@@ -665,9 +663,7 @@ public class AlertDispatchDAOTest {
   public void testAlertNoticePredicate() throws Exception {
     Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
-    // end the UnitOfWork to clean the cache
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
+
     m_alertHelper.populateData(cluster);
 
     Predicate clusterPredicate = null;
@@ -746,9 +742,6 @@ public class AlertDispatchDAOTest {
     Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
 
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
-
     m_alertHelper.populateData(cluster);
 
     AlertNoticeRequest request = new AlertNoticeRequest();
@@ -789,8 +782,6 @@ public class AlertDispatchDAOTest {
   public void testAlertNoticeSorting() throws Exception {
     Cluster cluster = m_helper.buildNewCluster(m_clusters, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
 
     m_alertHelper.populateData(cluster);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
index b224203..0bbe998 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
@@ -1175,10 +1175,6 @@ public class AlertsDAOTest {
   public void testAlertHistoryPredicate() throws Exception {
     m_helper.installHdfsService(m_cluster, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
-
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
-
     m_alertHelper.populateData(m_cluster);
 
     Predicate clusterPredicate = null;
@@ -1272,10 +1268,6 @@ public class AlertsDAOTest {
   public void testAlertHistoryPagination() throws Exception {
     m_helper.installHdfsService(m_cluster, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
-
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
-
     m_alertHelper.populateData(m_cluster);
 
     AlertHistoryRequest request = new AlertHistoryRequest();
@@ -1316,10 +1308,6 @@ public class AlertsDAOTest {
   public void testAlertHistorySorting() throws Exception {
     m_helper.installHdfsService(m_cluster, m_serviceFactory,
         m_componentFactory, m_schFactory, HOSTNAME);
-
-    m_injector.getInstance(UnitOfWork.class).end();
-    m_injector.getInstance(UnitOfWork.class).begin();
-
     m_alertHelper.populateData(m_cluster);
 
     List<SortRequestProperty> sortProperties = new ArrayList<SortRequestProperty>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4fb9ed/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
index 5509869..edc1428 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
@@ -48,7 +48,6 @@ import org.junit.Test;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.persist.PersistService;
-import com.google.inject.persist.UnitOfWork;
 
 /**
  * RequestDAO unit tests
@@ -72,13 +71,11 @@ public class RequestDAOTest {
     hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
     hostDAO = injector.getInstance(HostDAO.class);
     requestDAO = injector.getInstance(RequestDAO.class);
-    injector.getInstance(UnitOfWork.class).begin();
 
   }
 
   @After
   public void teardown() throws AmbariException {
-    injector.getInstance(UnitOfWork.class).end();
     injector.getInstance(PersistService.class).stop();
   }
 


Mime
View raw message