This is an automated email from the ASF dual-hosted git repository.
journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new e9fcf61 AlertMappert UT modify #1465 (#1616)
e9fcf61 is described below
commit e9fcf6128e051a642808c7815d1ebc30aa32aad6
Author: qiaozhanwei <[email protected]>
AuthorDate: Sun Dec 29 09:59:49 2019 +0800
AlertMappert UT modify #1465 (#1616)
* remove LogViewServiceGrpc.java file and pom modify
* remove kazoo
* remove kazoo
* remove kazoo
* remove common monitor package
* add license
* remove kazoo modify
* remove kazoo modify
* remove kazoo modify
* remove kazoo modify
* remove kazoo modify
* remove kazoo modify
* install.sh remove python kazoo
* add system param whether repeat running
* remove kazoo modify
* BusinessTimeUtils remove whther repeat running inner param
* add AccessTokenMapperTest UT
* CI UT yml modify,start postgresql and zookeeper by default
* add AlertGroupMapperTest UT in github action
* Conflicts reslove
* AlertMappert UT modify
* AlertMappert UT modify
* AlertMappert UT modify
---
.../apache/dolphinscheduler/dao/entity/Alert.java | 71 +++++++++-
.../dao/mapper/AlertMapperTest.java | 153 +++++++++++++++------
pom.xml | 1 +
3 files changed, 177 insertions(+), 48 deletions(-)
diff --git
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
index d989f82..dac96e8 100644
---
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
+++
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
@@ -32,7 +32,6 @@ import java.util.Map;
/**
* alert
*/
-@Data
@TableName("t_ds_alert")
public class Alert {
@@ -218,6 +217,72 @@ public class Alert {
}
@Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Alert alert = (Alert) o;
+
+ if (id != alert.id) {
+ return false;
+ }
+ if (alertGroupId != alert.alertGroupId) {
+ return false;
+ }
+ if (!title.equals(alert.title)) {
+ return false;
+ }
+ if (showType != alert.showType) {
+ return false;
+ }
+ if (!content.equals(alert.content)) {
+ return false;
+ }
+ if (alertType != alert.alertType) {
+ return false;
+ }
+ if (alertStatus != alert.alertStatus) {
+ return false;
+ }
+ if (!log.equals(alert.log)) {
+ return false;
+ }
+ if (!receivers.equals(alert.receivers)) {
+ return false;
+ }
+ if (!receiversCc.equals(alert.receiversCc)) {
+ return false;
+ }
+ if (!createTime.equals(alert.createTime)) {
+ return false;
+ }
+ return updateTime.equals(alert.updateTime) && info.equals(alert.info);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + title.hashCode();
+ result = 31 * result + showType.hashCode();
+ result = 31 * result + content.hashCode();
+ result = 31 * result + alertType.hashCode();
+ result = 31 * result + alertStatus.hashCode();
+ result = 31 * result + log.hashCode();
+ result = 31 * result + alertGroupId;
+ result = 31 * result + receivers.hashCode();
+ result = 31 * result + receiversCc.hashCode();
+ result = 31 * result + createTime.hashCode();
+ result = 31 * result + updateTime.hashCode();
+ result = 31 * result + info.hashCode();
+ return result;
+ }
+
+ @Override
public String toString() {
return "Alert{" +
"id=" + id +
@@ -228,10 +293,10 @@ public class Alert {
", alertStatus=" + alertStatus +
", log='" + log + '\'' +
", alertGroupId=" + alertGroupId +
- ", createTime=" + createTime +
- ", updateTime=" + updateTime +
", receivers='" + receivers + '\'' +
", receiversCc='" + receiversCc + '\'' +
+ ", createTime=" + createTime +
+ ", updateTime=" + updateTime +
", info=" + info +
'}';
}
diff --git
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
index 958cd39..5f10a75 100644
---
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
+++
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
@@ -19,44 +19,52 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AlertStatus;
import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.Alert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
-import java.util.Date;
-import java.util.List;
-
+import java.util.*;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
+@Transactional
+@Rollback(true)
public class AlertMapperTest {
@Autowired
- AlertMapper alertMapper;
+ private AlertMapper alertMapper;
/**
- * insert
- * @return Alert
+ * test insert
+ * @return
*/
- private Alert insertOne(){
- //insertOne
- Alert alert = new Alert();
-
alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server
down','warning level':'serious'}]");
- alert.setLog("success");
- alert.setReceivers("[email protected]");
- alert.setAlertType(AlertType.EMAIL);
- alert.setShowType(ShowType.TABLE);
- alert.setAlertGroupId(1);
- alert.setAlertStatus(AlertStatus.EXECUTION_SUCCESS);
- alert.setCreateTime(new Date());
- alert.setUpdateTime(new Date());
- alertMapper.insert(alert);
- return alert;
+ @Test
+ public void testInsert(){
+ Alert expectedAlert = createAlert();
+ assertNotNull(expectedAlert.getId());
+ assertThat(expectedAlert.getId(), greaterThan(0));
+ }
+
+
+ /**
+ * test select by id
+ * @return
+ */
+ @Test
+ public void testSelectById(){
+ Alert expectedAlert = createAlert();
+ Alert actualAlert = alertMapper.selectById(expectedAlert.getId());
+ assertEquals(expectedAlert, actualAlert);
}
/**
@@ -64,13 +72,18 @@ public class AlertMapperTest {
*/
@Test
public void testUpdate(){
- //insertOne
- Alert alert = insertOne();
- //update
- alert.setTitle("hello");
- int update = alertMapper.updateById(alert);
- Assert.assertEquals(update, 1);
- alertMapper.deleteById(alert.getId());
+
+ Alert expectedAlert = createAlert();
+
+ expectedAlert.setAlertStatus(AlertStatus.EXECUTION_FAILURE);
+ expectedAlert.setLog("error");
+ expectedAlert.setUpdateTime(DateUtils.getCurrentDate());
+
+ alertMapper.updateById(expectedAlert);
+
+ Alert actualAlert = alertMapper.selectById(expectedAlert.getId());
+
+ assertEquals(expectedAlert, actualAlert);
}
/**
@@ -78,33 +91,83 @@ public class AlertMapperTest {
*/
@Test
public void testDelete(){
+ Alert expectedAlert = createAlert();
- Alert alert = insertOne();
- int delete = alertMapper.deleteById(alert.getId());
- Assert.assertEquals(delete, 1);
+ alertMapper.deleteById(expectedAlert.getId());
+
+ Alert actualAlert = alertMapper.selectById(expectedAlert.getId());
+
+ assertNull(actualAlert);
}
+
/**
- * test query
+ * test list alert by status
*/
@Test
- public void testQuery() {
- Alert alert = insertOne();
- //query
- List<Alert> alerts = alertMapper.selectList(null);
- Assert.assertNotEquals(alerts.size(), 0);
- alertMapper.deleteById(alert.getId());
+ public void testListAlertByStatus() {
+ Integer count = 10;
+ AlertStatus waitExecution = AlertStatus.WAIT_EXECUTION;
+
+ Map<Integer,Alert> expectedAlertMap = createAlertMap(count,
waitExecution);
+
+ 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
- public void testListAlertByStatus() {
- Alert alert = insertOne();
- //query
- List<Alert> alerts =
alertMapper.listAlertByStatus(AlertStatus.EXECUTION_SUCCESS);
- Assert.assertNotEquals(alerts.size(), 0);
- alertMapper.deleteById(alert.getId());
+ private Map<Integer,Alert> createAlertMap(Integer count,AlertStatus
alertStatus){
+ Map<Integer,Alert> alertMap = new HashMap<>();
+
+ for (int i = 0 ; i < count ;i++){
+ Alert alert = createAlert(alertStatus);
+ alertMap.put(alert.getId(),alert);
+ }
+
+ 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("[email protected]");
+ alert.setReceiversCc("[email protected]");
+ alert.setCreateTime(DateUtils.getCurrentDate());
+ alert.setUpdateTime(DateUtils.getCurrentDate());
+
+ alertMapper.insert(alert);
+ return alert;
}
}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 69f1ff0..796d2b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -674,6 +674,7 @@
<include>**/server/utils/FlinkArgsUtilsTest.java</include>
<include>**/dao/mapper/AccessTokenMapperTest.java</include>
<include>**/dao/mapper/AlertGroupMapperTest.java</include>
+
<include>**/dao/mapper/AlertMapperTest.java</include>
</includes>
<!-- <skip>true</skip> -->
</configuration>