|
@@ -17,9 +17,7 @@
|
|
|
|
|
|
package org.apache.dolphinscheduler.dao.mapper;
|
|
|
|
|
|
-import org.apache.dolphinscheduler.common.utils.DateUtils;
|
|
|
import org.apache.dolphinscheduler.dao.BaseDaoTest;
|
|
|
-import org.apache.dolphinscheduler.dao.entity.AlertGroup;
|
|
|
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
|
|
|
import org.apache.dolphinscheduler.dao.entity.PluginDefine;
|
|
|
|
|
@@ -29,6 +27,9 @@ import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+
|
|
|
/**
|
|
|
* AlertPluginInstanceMapper mapper test
|
|
|
*/
|
|
@@ -40,73 +41,76 @@ public class AlertPluginInstanceMapperTest extends BaseDaoTest {
|
|
|
@Autowired
|
|
|
private PluginDefineMapper pluginDefineMapper;
|
|
|
|
|
|
- @Autowired
|
|
|
- private AlertGroupMapper alertGroupMapper;
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Test function queryAllAlertPluginInstanceList behavior with different size.
|
|
|
+ */
|
|
|
@Test
|
|
|
public void testQueryAllAlertPluginInstanceList() {
|
|
|
- createAlertPluginInstance();
|
|
|
- List<AlertPluginInstance> alertPluginInstanceList = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
|
|
|
- Assert.assertTrue(alertPluginInstanceList.size() > 0);
|
|
|
- }
|
|
|
+ List<AlertPluginInstance> withoutSingleOne = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
|
|
|
+ Assert.assertEquals(0, withoutSingleOne.size());
|
|
|
|
|
|
- @Test
|
|
|
- public void testQueryByAlertGroupId() {
|
|
|
- createAlertPluginInstance();
|
|
|
- List<AlertGroup> testAlertGroupList = alertGroupMapper.queryByGroupName("test_group_01");
|
|
|
- Assert.assertNotNull(testAlertGroupList);
|
|
|
- Assert.assertTrue(testAlertGroupList.size() > 0);
|
|
|
- AlertGroup alertGroup = testAlertGroupList.get(0);
|
|
|
+ createAlertPluginInstance("test_instance_1");
|
|
|
+ List<AlertPluginInstance> withExactlyOne = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
|
|
|
+ Assert.assertEquals(1, withExactlyOne.size());
|
|
|
+
|
|
|
+ createAlertPluginInstance("test_instance_2");
|
|
|
+ List<AlertPluginInstance> withExactlyTwo = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
|
|
|
+ Assert.assertEquals(2, withExactlyTwo.size());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test function existInstanceName with init status and single record status.
|
|
|
+ */
|
|
|
@Test
|
|
|
public void testExistInstanceName() {
|
|
|
String instanceName = "test_instance";
|
|
|
Assert.assertNull(alertPluginInstanceMapper.existInstanceName(instanceName));
|
|
|
- createAlertPluginInstance();
|
|
|
+ createAlertPluginInstance(instanceName);
|
|
|
Assert.assertTrue(alertPluginInstanceMapper.existInstanceName(instanceName));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * insert
|
|
|
- *
|
|
|
- * @return AlertPluginInstance
|
|
|
+ * Test function queryByInstanceNamePage returning with different search variables.
|
|
|
*/
|
|
|
- private AlertPluginInstance createAlertPluginInstance() {
|
|
|
+ @Test
|
|
|
+ public void testQueryByInstanceNamePage() {
|
|
|
+ createAlertPluginInstance("test_with_pattern_instance");
|
|
|
+ createAlertPluginInstance("test_no_instance");
|
|
|
|
|
|
- PluginDefine pluginDefine = createPluginDefine();
|
|
|
- AlertGroup alertGroup = createAlertGroup("test_group_01");
|
|
|
- AlertPluginInstance alertPluginInstance = new AlertPluginInstance(pluginDefine.getId(), "", "test_instance");
|
|
|
- alertPluginInstanceMapper.insert(alertPluginInstance);
|
|
|
- return alertPluginInstance;
|
|
|
+ Page<AlertPluginInstance> page = new Page<>(1, 10);
|
|
|
+ IPage<AlertPluginInstance> matchTwoRecord = alertPluginInstanceMapper.queryByInstanceNamePage(page, "test");
|
|
|
+ Assert.assertEquals(2, matchTwoRecord.getTotal());
|
|
|
+
|
|
|
+ IPage<AlertPluginInstance> matchOneRecord = alertPluginInstanceMapper.queryByInstanceNamePage(page, "pattern");
|
|
|
+ Assert.assertEquals(1, matchOneRecord.getTotal());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * insert
|
|
|
- *
|
|
|
- * @return PluginDefine
|
|
|
+ * Create alert plugin instance according to given alter plugin name.
|
|
|
*/
|
|
|
- private PluginDefine createPluginDefine() {
|
|
|
- PluginDefine pluginDefine = new PluginDefine("test plugin", "alert", "");
|
|
|
- pluginDefineMapper.insert(pluginDefine);
|
|
|
- return pluginDefine;
|
|
|
+ private void createAlertPluginInstance(String alterPluginInsName) {
|
|
|
+ PluginDefine pluginDefine = makeSurePluginDefineExists();
|
|
|
+ AlertPluginInstance alertPluginInstance = new AlertPluginInstance(pluginDefine.getId(), "", alterPluginInsName);
|
|
|
+ alertPluginInstanceMapper.insert(alertPluginInstance);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * insert
|
|
|
+ * Make sure plugin define exists.
|
|
|
+ * <p>
|
|
|
+ * Create a new plugin define if not exists, else just return exists plugin define
|
|
|
*
|
|
|
- * @return AlertGroup
|
|
|
+ * @return PluginDefine
|
|
|
*/
|
|
|
- private AlertGroup createAlertGroup(String groupName) {
|
|
|
- AlertGroup alertGroup = new AlertGroup();
|
|
|
- alertGroup.setGroupName(groupName);
|
|
|
- alertGroup.setDescription("alert group 1");
|
|
|
-
|
|
|
- alertGroup.setCreateTime(DateUtils.getCurrentDate());
|
|
|
- alertGroup.setUpdateTime(DateUtils.getCurrentDate());
|
|
|
-
|
|
|
- alertGroupMapper.insert(alertGroup);
|
|
|
-
|
|
|
- return alertGroup;
|
|
|
+ private PluginDefine makeSurePluginDefineExists() {
|
|
|
+ String pluginName = "test plugin";
|
|
|
+ String pluginType = "alert";
|
|
|
+ PluginDefine pluginDefine = pluginDefineMapper.queryByNameAndType(pluginName, pluginType);
|
|
|
+ if (pluginDefine == null) {
|
|
|
+ PluginDefine newPluginDefine = new PluginDefine(pluginName, pluginType, "");
|
|
|
+ pluginDefineMapper.insert(newPluginDefine);
|
|
|
+ return newPluginDefine;
|
|
|
+ } else {
|
|
|
+ return pluginDefine;
|
|
|
+ }
|
|
|
}
|
|
|
}
|