|
|
@ -19,44 +19,52 @@ package org.apache.dolphinscheduler.dao.mapper; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ShowType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ShowType; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Alert; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Alert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
|
|
|
|
import org.springframework.test.annotation.Rollback; |
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@RunWith(SpringRunner.class) |
|
|
|
@SpringBootTest |
|
|
|
@SpringBootTest |
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
@Rollback(true) |
|
|
|
public class AlertMapperTest { |
|
|
|
public class AlertMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
AlertMapper alertMapper; |
|
|
|
private AlertMapper alertMapper; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert |
|
|
|
* test insert |
|
|
|
* @return Alert |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Alert insertOne(){ |
|
|
|
@Test |
|
|
|
//insertOne
|
|
|
|
public void testInsert(){ |
|
|
|
Alert alert = new Alert(); |
|
|
|
Alert expectedAlert = createAlert(); |
|
|
|
alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]"); |
|
|
|
assertNotNull(expectedAlert.getId()); |
|
|
|
alert.setLog("success"); |
|
|
|
assertThat(expectedAlert.getId(), greaterThan(0)); |
|
|
|
alert.setReceivers("xx@aa.com"); |
|
|
|
} |
|
|
|
alert.setAlertType(AlertType.EMAIL); |
|
|
|
|
|
|
|
alert.setShowType(ShowType.TABLE); |
|
|
|
|
|
|
|
alert.setAlertGroupId(1); |
|
|
|
/** |
|
|
|
alert.setAlertStatus(AlertStatus.EXECUTION_SUCCESS); |
|
|
|
* test select by id |
|
|
|
alert.setCreateTime(new Date()); |
|
|
|
* @return |
|
|
|
alert.setUpdateTime(new Date()); |
|
|
|
*/ |
|
|
|
alertMapper.insert(alert); |
|
|
|
@Test |
|
|
|
return alert; |
|
|
|
public void testSelectById(){ |
|
|
|
|
|
|
|
Alert expectedAlert = createAlert(); |
|
|
|
|
|
|
|
Alert actualAlert = alertMapper.selectById(expectedAlert.getId()); |
|
|
|
|
|
|
|
assertEquals(expectedAlert, actualAlert); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -64,13 +72,18 @@ public class AlertMapperTest { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdate(){ |
|
|
|
public void testUpdate(){ |
|
|
|
//insertOne
|
|
|
|
|
|
|
|
Alert alert = insertOne(); |
|
|
|
Alert expectedAlert = createAlert(); |
|
|
|
//update
|
|
|
|
|
|
|
|
alert.setTitle("hello"); |
|
|
|
expectedAlert.setAlertStatus(AlertStatus.EXECUTION_FAILURE); |
|
|
|
int update = alertMapper.updateById(alert); |
|
|
|
expectedAlert.setLog("error"); |
|
|
|
Assert.assertEquals(update, 1); |
|
|
|
expectedAlert.setUpdateTime(DateUtils.getCurrentDate()); |
|
|
|
alertMapper.deleteById(alert.getId()); |
|
|
|
|
|
|
|
|
|
|
|
alertMapper.updateById(expectedAlert); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Alert actualAlert = alertMapper.selectById(expectedAlert.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedAlert, actualAlert); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -78,33 +91,83 @@ public class AlertMapperTest { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDelete(){ |
|
|
|
public void testDelete(){ |
|
|
|
|
|
|
|
Alert expectedAlert = createAlert(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alertMapper.deleteById(expectedAlert.getId()); |
|
|
|
|
|
|
|
|
|
|
|
Alert alert = insertOne(); |
|
|
|
Alert actualAlert = alertMapper.selectById(expectedAlert.getId()); |
|
|
|
int delete = alertMapper.deleteById(alert.getId()); |
|
|
|
|
|
|
|
Assert.assertEquals(delete, 1); |
|
|
|
assertNull(actualAlert); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test query |
|
|
|
* test list alert by status |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQuery() { |
|
|
|
public void testListAlertByStatus() { |
|
|
|
Alert alert = insertOne(); |
|
|
|
Integer count = 10; |
|
|
|
//query
|
|
|
|
AlertStatus waitExecution = AlertStatus.WAIT_EXECUTION; |
|
|
|
List<Alert> alerts = alertMapper.selectList(null); |
|
|
|
|
|
|
|
Assert.assertNotEquals(alerts.size(), 0); |
|
|
|
Map<Integer,Alert> expectedAlertMap = createAlertMap(count, waitExecution); |
|
|
|
alertMapper.deleteById(alert.getId()); |
|
|
|
|
|
|
|
|
|
|
|
List<Alert> actualAlerts = alertMapper.listAlertByStatus(waitExecution); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Alert actualAlert : actualAlerts){ |
|
|
|
|
|
|
|
Alert expectedAlert = expectedAlertMap.get(actualAlert.getId()); |
|
|
|
|
|
|
|
if (expectedAlert != null){ |
|
|
|
|
|
|
|
assertEquals(expectedAlert,actualAlert); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test list alert by status |
|
|
|
* create alert map |
|
|
|
|
|
|
|
* @param count alert count |
|
|
|
|
|
|
|
* @param alertStatus alert status |
|
|
|
|
|
|
|
* @return alert map |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
private Map<Integer,Alert> createAlertMap(Integer count,AlertStatus alertStatus){ |
|
|
|
public void testListAlertByStatus() { |
|
|
|
Map<Integer,Alert> alertMap = new HashMap<>(); |
|
|
|
Alert alert = insertOne(); |
|
|
|
|
|
|
|
//query
|
|
|
|
for (int i = 0 ; i < count ;i++){ |
|
|
|
List<Alert> alerts = alertMapper.listAlertByStatus(AlertStatus.EXECUTION_SUCCESS); |
|
|
|
Alert alert = createAlert(alertStatus); |
|
|
|
Assert.assertNotEquals(alerts.size(), 0); |
|
|
|
alertMap.put(alert.getId(),alert); |
|
|
|
alertMapper.deleteById(alert.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return alertMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create alert |
|
|
|
|
|
|
|
* @return alert |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Alert createAlert(){ |
|
|
|
|
|
|
|
return createAlert(AlertStatus.WAIT_EXECUTION); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* create alert |
|
|
|
|
|
|
|
* @param alertStatus alert status |
|
|
|
|
|
|
|
* @return alert |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Alert createAlert(AlertStatus alertStatus){ |
|
|
|
|
|
|
|
Alert alert = new Alert(); |
|
|
|
|
|
|
|
alert.setShowType(ShowType.TABLE); |
|
|
|
|
|
|
|
alert.setTitle("test alert"); |
|
|
|
|
|
|
|
alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]"); |
|
|
|
|
|
|
|
alert.setAlertType(AlertType.EMAIL); |
|
|
|
|
|
|
|
alert.setAlertStatus(alertStatus); |
|
|
|
|
|
|
|
alert.setLog("success"); |
|
|
|
|
|
|
|
alert.setReceivers("aa@aa.com"); |
|
|
|
|
|
|
|
alert.setReceiversCc("bb@aa.com"); |
|
|
|
|
|
|
|
alert.setCreateTime(DateUtils.getCurrentDate()); |
|
|
|
|
|
|
|
alert.setUpdateTime(DateUtils.getCurrentDate()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alertMapper.insert(alert); |
|
|
|
|
|
|
|
return alert; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |