diff options
-rw-r--r-- | holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java | 8 | ||||
-rw-r--r-- | holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java | 13 |
2 files changed, 17 insertions, 4 deletions
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java index 8cb3d2b..21b62f3 100644 --- a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java +++ b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java @@ -55,14 +55,18 @@ public class MQProducer { Serializable msgEntity = (Serializable) t;
Connection connection = null;
Session session;
- Destination destination;
+ Destination destination = null;
MessageProducer messageProducer;
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);
+ if (t instanceof CorrelationResult) {
+ destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);
+ } else if (t instanceof Alarm) {
+ destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);
+ }
messageProducer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage(msgEntity);
messageProducer.send(message);
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java index 49858ab..c42ee60 100644 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java +++ b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java @@ -16,6 +16,7 @@ package org.openo.holmes.common.api.stat; +import java.util.Date; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -84,8 +85,16 @@ public class AlarmTest { @Test public void testToString() throws Exception { - final Alarm alarmTemp = new Alarm(); - assertThat(alarmTemp.toString(), equalTo(alarm.toString())); + Alarm alarmTempA = new Alarm(); + Alarm alarmTempB = new Alarm(); + Date date = new Date(); + alarmTempA.setClearedTime(date); + alarmTempA.setRaisedTime(date); + alarmTempA.setRaisedServerTime(date); + alarmTempB.setClearedTime(date); + alarmTempB.setRaisedTime(date); + alarmTempB.setRaisedServerTime(date); + assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString())); } @Test |