Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 730EE17287 for ; Thu, 26 Mar 2015 13:30:10 +0000 (UTC) Received: (qmail 43581 invoked by uid 500); 26 Mar 2015 13:30:02 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 43557 invoked by uid 500); 26 Mar 2015 13:30:02 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 43548 invoked by uid 99); 26 Mar 2015 13:30:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Mar 2015 13:30:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 21D0DE2C0A; Thu, 26 Mar 2015 13:30:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jonathanhurley@apache.org To: commits@ambari.apache.org Message-Id: <6aede3b34d4a47f5b5867eb799060783@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-9823 - Alert Notifications Are Not Received Without Restarting Ambari Server (part2) (jonathanhurley) Date: Thu, 26 Mar 2015 13:30:02 +0000 (UTC) Repository: ambari Updated Branches: refs/heads/trunk 2c2645767 -> 2ae23688c AMBARI-9823 - Alert Notifications Are Not Received Without Restarting Ambari Server (part2) (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2ae23688 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2ae23688 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2ae23688 Branch: refs/heads/trunk Commit: 2ae23688c6f9d54d2355f173eae89694c77ec697 Parents: 2c26457 Author: Jonathan Hurley Authored: Wed Mar 25 19:36:39 2015 -0400 Committer: Jonathan Hurley Committed: Thu Mar 26 09:29:55 2015 -0400 ---------------------------------------------------------------------- .../server/orm/entities/AlertGroupEntity.java | 2 +- .../server/orm/dao/AlertDispatchDAOTest.java | 38 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/2ae23688/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 7d2c6c7..9efb166 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 @@ -82,7 +82,7 @@ public class AlertGroupEntity { /** * Unidirectional many-to-many association to {@link AlertTargetEntity} */ - @ManyToMany(cascade = CascadeType.MERGE) + @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) }) private Set alertTargets; http://git-wip-us.apache.org/repos/asf/ambari/blob/2ae23688/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 a267043..8768ffc 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 @@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -584,6 +585,43 @@ public class AlertDispatchDAOTest { } /** + * Tests finding groups by a definition ID that they are associatd with in + * order to get any targets associated with that group. This exercises the + * bi-directional + * + * @throws Exception + */ + @Test + public void testFindTargetsViaGroupsByDefinition() throws Exception { + List definitions = createDefinitions(); + AlertGroupEntity group = m_helper.createAlertGroup( + m_cluster.getClusterId(), null); + + group = m_dao.findGroupById(group.getGroupId()); + assertNotNull(group); + + AlertDefinitionEntity definition = definitions.get(0); + group.addAlertDefinition(definition); + + m_dao.merge(group); + + List targets = m_dao.findAllTargets(); + AlertTargetEntity target = targets.get(0); + Set setTargets = Collections.singleton(target); + + group.setAlertTargets(setTargets); + m_dao.merge(group); + + List groups = m_dao.findGroupsByDefinition(definition); + assertEquals(2, groups.size()); + + group = groups.get(groups.indexOf(group)); + assertEquals(1, group.getAlertTargets().size()); + assertEquals(target.getTargetId(), + group.getAlertTargets().iterator().next().getTargetId()); + } + + /** * @throws Exception */ @Test