Browse Source

Fix unit tests

chengshiwen 4 years ago
parent
commit
4be5e159cb
  1. 13
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPlugin.java
  2. 3
      dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
  3. 6
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

13
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPlugin.java

@ -96,9 +96,6 @@ public class EmailAlertPlugin implements AlertPlugin {
retMaps = emailManager.send(receviersList, receviersCcList, alert.getTitle(), alert.getContent(),
alert.getShowType());
//send flag
boolean flag = false;
if (retMaps == null) {
retMaps = new HashMap<>();
retMaps.put(Constants.MESSAGE, "alert send error.");
@ -107,9 +104,12 @@ public class EmailAlertPlugin implements AlertPlugin {
return retMaps;
}
flag = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)));
if (flag) {
boolean enabled = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.MAIL_ENABLED)));
boolean status = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)));
if (!enabled) {
logger.warn("mail wasn't sent since the mail config isn't set");
retMaps.put(Constants.MESSAGE, "mail wasn't sent since the mail config isn't set");
} else if (status) {
logger.info("alert send success");
retMaps.put(Constants.MESSAGE, "email send success.");
if (EnterpriseWeChatUtils.isEnable()) {
@ -121,7 +121,6 @@ public class EmailAlertPlugin implements AlertPlugin {
logger.error(e.getMessage(), e);
}
}
} else {
retMaps.put(Constants.MESSAGE, "alert send error.");
logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE));

3
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java

@ -75,6 +75,7 @@ public class EmailAlertPluginTest {
List<String> list = new ArrayList<String>(){{ add("xx@xx.com"); }};
alertInfo.addProp("receivers", list);
Map<String, Object> ret = plugin.process(alertInfo);
assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS))));
assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.MAIL_ENABLED))));
assertTrue(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS))));
}
}

6
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

@ -453,11 +453,11 @@ public class SqlTask extends AbstractTask {
if(EnumUtils.isValidEnum(ShowType.class,showTypeName)){
Map<String, Object> mailResult = MailUtils.sendMails(receiversList,
receiversCcList, title, content, ShowType.valueOf(showTypeName).getDescp());
if(!(boolean) mailResult.get(STATUS)){
throw new RuntimeException("send mail failed!");
}else if(!(boolean) mailResult.get(MAIL_ENABLED)){
if(!(boolean) mailResult.get(MAIL_ENABLED)){
logger.info("mail info : {} {}", title, content);
logger.warn("mail wasn't sent since the mail config isn't set");
}else if(!(boolean) mailResult.get(STATUS)){
throw new RuntimeException("send mail failed!");
}
}else{
logger.error("showType: {} is not valid " ,showTypeName);

Loading…
Cancel
Save