ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-18652 - Alert Targets Cannot Be Updated Due To Transaction / Cache Timing Issues (jonathanhurley)
Date Fri, 21 Oct 2016 17:16:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 7f26a6ae8 -> a132f9c00


AMBARI-18652 - Alert Targets Cannot Be Updated Due To Transaction / Cache Timing Issues (jonathanhurley)


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

Branch: refs/heads/branch-2.5
Commit: a132f9c00210836dfd576a06437db0c497ab3b23
Parents: 7f26a6a
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Thu Oct 20 12:59:04 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Fri Oct 21 13:15:16 2016 -0400

----------------------------------------------------------------------
 .../internal/AlertTargetResourceProvider.java   |  7 ++-
 .../ambari/server/orm/dao/AlertDispatchDAO.java | 56 ++++++++++++--------
 .../server/orm/entities/AlertGroupEntity.java   | 54 ++++++++++++++-----
 .../server/orm/entities/AlertNoticeEntity.java  | 18 +++----
 .../server/orm/entities/AlertTargetEntity.java  | 30 ++++++++---
 .../AlertTargetResourceProviderTest.java        |  5 --
 .../alerts/AlertStateChangedEventTest.java      | 11 ++--
 .../AlertNoticeDispatchServiceTest.java         | 13 ++---
 8 files changed, 124 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
index 48a5183..8e5674e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
@@ -57,6 +57,7 @@ import org.apache.commons.lang.StringUtils;
 
 import com.google.gson.Gson;
 import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
 
 /**
  * The {@link AlertTargetResourceProvider} class deals with managing the CRUD
@@ -371,6 +372,7 @@ public class AlertTargetResourceProvider extends
    * @throws AmbariException
    *           if the entity could not be found.
    */
+  @Transactional
   @SuppressWarnings("unchecked")
   private void updateAlertTargets(long alertTargetId,
       Map<String, Object> requestMap)
@@ -447,13 +449,10 @@ public class AlertTargetResourceProvider extends
       entity.setAlertGroups(groups);
     } else if (entity.isGlobal()){
       Set<AlertGroupEntity> groups = new HashSet<AlertGroupEntity>(s_dao.findAllGroups());
-      for (AlertGroupEntity group : groups) {
-        group.addAlertTarget(entity);
-        s_dao.merge(group);
-      }
       entity.setAlertGroups(groups);
     }
 
+    // merge the entity, cascading the merge to other entities, like groups
     s_dao.merge(entity);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/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 4ffb802..3b9c97a 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
@@ -17,10 +17,19 @@
  */
 package org.apache.ambari.server.orm.dao;
 
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import com.google.inject.persist.Transactional;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Order;
+import javax.persistence.metamodel.SingularAttribute;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.query.JpaPredicateVisitor;
 import org.apache.ambari.server.api.query.JpaSortBuilder;
@@ -43,16 +52,10 @@ import org.eclipse.persistence.config.QueryHints;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Order;
-import javax.persistence.metamodel.SingularAttribute;
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
 
 /**
  * The {@link AlertDispatchDAO} class manages the {@link AlertTargetEntity},
@@ -562,20 +565,29 @@ public class AlertDispatchDAO {
   }
 
   /**
-   * Persists new alert notices.
+   * Creates new alert notices using the {@link EntityManager#merge(Object)}
+   * method to ensure that the associated {@link AlertTargetEntity} instances
+   * are also updated.
+   * <p/>
+   * The method returns the newly managed entities as the ones passed in will
+   * not be managed.
    *
    * @param entities
-   *          the targets to persist (not {@code null}).
+   *          the targets to create (not {@code null}).
    */
   @Transactional
-  public void createNotices(List<AlertNoticeEntity> entities) {
-    if (null == entities) {
-      return;
+  public List<AlertNoticeEntity> createNotices(List<AlertNoticeEntity> entities)
{
+    if (null == entities || entities.isEmpty()) {
+      return entities;
     }
 
+    List<AlertNoticeEntity> managedEntities = new ArrayList<>(entities.size());
     for (AlertNoticeEntity entity : entities) {
-      create(entity);
+      AlertNoticeEntity managedEntity = merge(entity);
+      managedEntities.add(managedEntity);
     }
+
+    return managedEntities;
   }
 
   /**
@@ -628,7 +640,7 @@ public class AlertDispatchDAO {
    */
   @Transactional
   public void remove(AlertTargetEntity alertTarget) {
-    entityManagerProvider.get().remove(merge(alertTarget));
+    entityManagerProvider.get().remove(alertTarget);
   }
 
   /**
@@ -673,7 +685,7 @@ public class AlertDispatchDAO {
    */
   @Transactional
   public void remove(AlertNoticeEntity alertNotice) {
-    entityManagerProvider.get().remove(merge(alertNotice));
+    entityManagerProvider.get().remove(alertNotice);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
index 0d6d151..76c6b62 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
@@ -24,6 +24,7 @@ import java.util.Set;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -42,17 +43,38 @@ import javax.persistence.UniqueConstraint;
  * {@link AlertTargetEntity} should be notified on.
  */
 @Entity
-@Table(name = "alert_group", uniqueConstraints = @UniqueConstraint(columnNames = {
-    "cluster_id", "group_name" }))
-@TableGenerator(name = "alert_group_id_generator", table = "ambari_sequences", pkColumnName
= "sequence_name", valueColumnName = "sequence_value", pkColumnValue = "alert_group_id_seq",
initialValue = 0)
+@Table(
+    name = "alert_group",
+    uniqueConstraints = @UniqueConstraint(columnNames = { "cluster_id", "group_name" }))
+@TableGenerator(
+    name = "alert_group_id_generator",
+    table = "ambari_sequences",
+    pkColumnName = "sequence_name",
+    valueColumnName = "sequence_value",
+    pkColumnValue = "alert_group_id_seq",
+    initialValue = 0)
 @NamedQueries({
-    @NamedQuery(name = "AlertGroupEntity.findAll", query = "SELECT alertGroup FROM AlertGroupEntity
alertGroup"),
-    @NamedQuery(name = "AlertGroupEntity.findAllInCluster", query = "SELECT alertGroup FROM
AlertGroupEntity alertGroup WHERE alertGroup.clusterId = :clusterId"),
-    @NamedQuery(name = "AlertGroupEntity.findByName", query = "SELECT alertGroup FROM AlertGroupEntity
alertGroup WHERE alertGroup.groupName = :groupName"),
-    @NamedQuery(name = "AlertGroupEntity.findByNameInCluster", query = "SELECT alertGroup
FROM AlertGroupEntity alertGroup WHERE alertGroup.groupName = :groupName AND alertGroup.clusterId
= :clusterId"),
-    @NamedQuery(name = "AlertGroupEntity.findByAssociatedDefinition", query = "SELECT alertGroup
FROM AlertGroupEntity alertGroup WHERE :alertDefinition MEMBER OF alertGroup.alertDefinitions"),
-    @NamedQuery(name = "AlertGroupEntity.findServiceDefaultGroup", query = "SELECT alertGroup
FROM AlertGroupEntity alertGroup WHERE alertGroup.clusterId = :clusterId AND alertGroup.serviceName
= :serviceName AND alertGroup.isDefault = 1"),
-    @NamedQuery(name = "AlertGroupEntity.findByIds", query = "SELECT alertGroup FROM AlertGroupEntity
alertGroup WHERE alertGroup.groupId IN :groupIds") })
+    @NamedQuery(
+        name = "AlertGroupEntity.findAll",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findAllInCluster",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE alertGroup.clusterId
= :clusterId"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findByName",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE alertGroup.groupName
= :groupName"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findByNameInCluster",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE alertGroup.groupName
= :groupName AND alertGroup.clusterId = :clusterId"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findByAssociatedDefinition",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE :alertDefinition
MEMBER OF alertGroup.alertDefinitions"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findServiceDefaultGroup",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE alertGroup.clusterId
= :clusterId AND alertGroup.serviceName = :serviceName AND alertGroup.isDefault = 1"),
+    @NamedQuery(
+        name = "AlertGroupEntity.findByIds",
+        query = "SELECT alertGroup FROM AlertGroupEntity alertGroup WHERE alertGroup.groupId
IN :groupIds") })
 public class AlertGroupEntity {
 
   @Id
@@ -76,14 +98,20 @@ public class AlertGroupEntity {
    * Bi-directional many-to-many association to {@link AlertDefinitionEntity}
    */
   @ManyToMany(cascade = CascadeType.MERGE)
-  @JoinTable(name = "alert_grouping", joinColumns = { @JoinColumn(name = "group_id", nullable
= false) }, inverseJoinColumns = { @JoinColumn(name = "definition_id", nullable = false) })
+  @JoinTable(
+      name = "alert_grouping",
+      joinColumns = { @JoinColumn(name = "group_id", nullable = false) },
+      inverseJoinColumns = { @JoinColumn(name = "definition_id", nullable = false) })
   private Set<AlertDefinitionEntity> alertDefinitions;
 
   /**
    * Unidirectional many-to-many association to {@link AlertTargetEntity}
    */
-  @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
-  @JoinTable(name = "alert_group_target", joinColumns = { @JoinColumn(name = "group_id",
nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "target_id", nullable = false)
})
+  @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.REFRESH
})
+  @JoinTable(
+      name = "alert_group_target",
+      joinColumns = { @JoinColumn(name = "group_id", nullable = false) },
+      inverseJoinColumns = { @JoinColumn(name = "target_id", nullable = false) })
   private Set<AlertTargetEntity> alertTargets;
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/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 cb24354..ba86687 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
@@ -34,6 +34,7 @@ import javax.persistence.Table;
 import javax.persistence.TableGenerator;
 
 import org.apache.ambari.server.state.NotificationState;
+import org.apache.commons.lang.builder.EqualsBuilder;
 
 /**
  * The {@link AlertNoticeEntity} class represents the need to dispatch a
@@ -67,7 +68,7 @@ public class AlertNoticeEntity {
   private NotificationState notifyState;
 
   @Basic
-  @Column(nullable = false, length = 64)
+  @Column(nullable = false, length = 64, unique = true)
   private String uuid;
 
   /**
@@ -83,7 +84,7 @@ public class AlertNoticeEntity {
   /**
    * Bi-directional many-to-one association to {@link AlertTargetEntity}
    */
-  @ManyToOne(cascade = { CascadeType.REFRESH })
+  @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
   @JoinColumn(name = "target_id", nullable = false)
   private AlertTargetEntity alertTarget;
 
@@ -171,7 +172,7 @@ public class AlertNoticeEntity {
    */
   public void setAlertHistory(AlertHistoryEntity alertHistory) {
     this.alertHistory = alertHistory;
-    this.historyId = alertHistory.getAlertId();
+    historyId = alertHistory.getAlertId();
   }
 
   /**
@@ -225,12 +226,9 @@ public class AlertNoticeEntity {
 
     AlertNoticeEntity that = (AlertNoticeEntity) object;
 
-    if (notificationId != null ? !notificationId.equals(that.notificationId)
-        : that.notificationId != null) {
-      return false;
-    }
-
-    return true;
+    EqualsBuilder equalsBuilder = new EqualsBuilder();
+    equalsBuilder.append(uuid, that.uuid);
+    return equalsBuilder.isEquals();
   }
 
   /**
@@ -238,7 +236,7 @@ public class AlertNoticeEntity {
    */
   @Override
   public int hashCode() {
-    int result = null != notificationId ? notificationId.hashCode() : 0;
+    int result = null != uuid ? uuid.hashCode() : 0;
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java
index de21f2d..9668210 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java
@@ -33,6 +33,7 @@ import javax.persistence.Entity;
 import javax.persistence.EntityManager;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -56,12 +57,26 @@ import com.google.common.collect.ImmutableSet;
  */
 @Entity
 @Table(name = "alert_target")
-@TableGenerator(name = "alert_target_id_generator", table = "ambari_sequences", pkColumnName
= "sequence_name", valueColumnName = "sequence_value", pkColumnValue = "alert_target_id_seq",
initialValue = 0)
+@TableGenerator(
+    name = "alert_target_id_generator",
+    table = "ambari_sequences",
+    pkColumnName = "sequence_name",
+    valueColumnName = "sequence_value",
+    pkColumnValue = "alert_target_id_seq",
+    initialValue = 0)
 @NamedQueries({
-    @NamedQuery(name = "AlertTargetEntity.findAll", query = "SELECT alertTarget FROM AlertTargetEntity
alertTarget"),
-    @NamedQuery(name = "AlertTargetEntity.findAllGlobal", query = "SELECT alertTarget FROM
AlertTargetEntity alertTarget WHERE alertTarget.isGlobal = 1"),
-    @NamedQuery(name = "AlertTargetEntity.findByName", query = "SELECT alertTarget FROM AlertTargetEntity
alertTarget WHERE alertTarget.targetName = :targetName"),
-    @NamedQuery(name = "AlertTargetEntity.findByIds", query = "SELECT alertTarget FROM AlertTargetEntity
alertTarget WHERE alertTarget.targetId IN :targetIds") })
+    @NamedQuery(
+        name = "AlertTargetEntity.findAll",
+        query = "SELECT alertTarget FROM AlertTargetEntity alertTarget"),
+    @NamedQuery(
+        name = "AlertTargetEntity.findAllGlobal",
+        query = "SELECT alertTarget FROM AlertTargetEntity alertTarget WHERE alertTarget.isGlobal
= 1"),
+    @NamedQuery(
+        name = "AlertTargetEntity.findByName",
+        query = "SELECT alertTarget FROM AlertTargetEntity alertTarget WHERE alertTarget.targetName
= :targetName"),
+    @NamedQuery(
+        name = "AlertTargetEntity.findByIds",
+        query = "SELECT alertTarget FROM AlertTargetEntity alertTarget WHERE alertTarget.targetId
IN :targetIds") })
 public class AlertTargetEntity {
 
   @Id
@@ -92,7 +107,10 @@ public class AlertTargetEntity {
   /**
    * Bi-directional many-to-many association to {@link AlertGroupEntity}
    */
-  @ManyToMany(mappedBy = "alertTargets", cascade = {CascadeType.MERGE, CascadeType.REFRESH})
+  @ManyToMany(
+      fetch = FetchType.EAGER,
+      mappedBy = "alertTargets",
+      cascade = { CascadeType.MERGE, CascadeType.REFRESH })
   private Set<AlertGroupEntity> alertGroups;
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
index bcdb9ce..96b81fe 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
@@ -961,8 +961,6 @@ public class AlertTargetResourceProviderTest {
     AlertTargetEntity target = new AlertTargetEntity();
     expect(m_dao.findTargetById(ALERT_TARGET_ID)).andReturn(target).once();
 
-    Capture<AlertGroupEntity> groupEntityCapture = EasyMock.newCapture();
-
     //All Groups in the Database with CLuster ID = 1L
     List<AlertGroupEntity> groups = getMockGroupEntities();
 
@@ -971,9 +969,6 @@ public class AlertTargetResourceProviderTest {
 
     expect(m_dao.findGroupsById(EasyMock.eq(groupIds))).andReturn(groups).anyTimes();
     expect(m_dao.findAllGroups()).andReturn(groups).once();
-    for(AlertGroupEntity group: groups){
-      expect(m_dao.merge(capture(groupEntityCapture))).andReturn(group).once();
-    }
     expect(m_dao.merge(capture(entityCapture))).andReturn(target).anyTimes();
 
     //start execution with these Expectation setters

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java
index 15ffef0..5dd04d7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java
@@ -52,6 +52,7 @@ import org.easymock.EasyMockSupport;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import com.google.inject.Binder;
 import com.google.inject.Guice;
@@ -61,7 +62,6 @@ import com.google.inject.persist.PersistService;
 import com.google.inject.util.Modules;
 
 import junit.framework.Assert;
-import org.junit.experimental.categories.Category;
 
 /**
  * Tests that {@link AlertStateChangeEvent} instances cause
@@ -134,8 +134,9 @@ public class AlertStateChangedEventTest extends EasyMockSupport {
         dispatchDao.findGroupsByDefinition(EasyMock.anyObject(AlertDefinitionEntity.class))).andReturn(
         groups).once();
 
-    dispatchDao.createNotices((List<AlertNoticeEntity>) EasyMock.anyObject());
-    EasyMock.expectLastCall().once();
+    EasyMock.expect(
+        dispatchDao.createNotices((List<AlertNoticeEntity>) EasyMock.anyObject())).andReturn(
+            new ArrayList<AlertNoticeEntity>()).once();
 
     AlertDefinitionEntity definition = getMockAlertDefinition();
 
@@ -504,7 +505,9 @@ public class AlertStateChangedEventTest extends EasyMockSupport {
     EasyMock.expect(definition.getLabel()).andReturn("ambari-foo-alert").anyTimes();
     EasyMock.expect(definition.getDescription()).andReturn("Ambari Foo Alert").anyTimes();
 
-    dispatchDao.createNotices((List<AlertNoticeEntity>) EasyMock.anyObject());
+    EasyMock.expect(
+        dispatchDao.createNotices((List<AlertNoticeEntity>) EasyMock.anyObject())).andReturn(
+            new ArrayList<AlertNoticeEntity>()).once();
 
     AlertCurrentEntity current = getMockedAlertCurrentEntity();
     AlertHistoryEntity history = createNiceMock(AlertHistoryEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a132f9c0/ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java
index 3684439..07094a8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java
@@ -243,13 +243,14 @@ public class AlertNoticeDispatchServiceTest extends AlertNoticeDispatchService
{
   public void testSingleDispatch() throws Exception {
     MockSnmpDispatcher dispatcher = new MockSnmpDispatcher();
 
-    List<AlertNoticeEntity> notices = getSingleMockNotice(dispatcher.getType());
-    AlertNoticeEntity notice = notices.get(0);
+    List<AlertNoticeEntity> notices = getSnmpMockNotices();
+    AlertNoticeEntity notice1 = notices.get(0);
+    AlertNoticeEntity notice2 = notices.get(1);
 
-    EasyMock.expect(m_dao.findPendingNotices()).andReturn(getSnmpMockNotices()).once();
-    EasyMock.expect(m_dao.merge(notice)).andReturn(notice).atLeastOnce();
-    EasyMock.expect(m_dispatchFactory.getDispatcher("SNMP")).andReturn(
-        dispatcher).atLeastOnce();
+    EasyMock.expect(m_dao.findPendingNotices()).andReturn(notices).once();
+    EasyMock.expect(m_dao.merge(notice1)).andReturn(notice1).once();
+    EasyMock.expect(m_dao.merge(notice2)).andReturn(notice2).once();
+    EasyMock.expect(m_dispatchFactory.getDispatcher("SNMP")).andReturn(dispatcher).atLeastOnce();
 
     EasyMock.replay(m_dao, m_dispatchFactory);
 


Mime
View raw message