AlertManagerTest.java 3.9 KB
Newer Older
L
ligang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.escheduler.server.master;

import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.mapper.ProcessDefinitionMapper;
import cn.escheduler.dao.mapper.ProcessInstanceMapper;
import cn.escheduler.dao.mapper.TaskInstanceMapper;
import cn.escheduler.dao.model.ProcessDefinition;
import cn.escheduler.dao.model.ProcessInstance;
import cn.escheduler.dao.model.TaskInstance;
import cn.escheduler.server.utils.AlertManager;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;


/**
 *  alert manager test
 */
public class AlertManagerTest {

    private static final Logger logger = LoggerFactory.getLogger(AlertManagerTest.class);

    ProcessDefinitionMapper processDefinitionMapper;
    ProcessInstanceMapper processInstanceMapper;
    TaskInstanceMapper taskInstanceMapper;

    AlertManager alertManager;

    @Before
    public void before(){
        processDefinitionMapper = ConnectionFactory.getSqlSession().getMapper(ProcessDefinitionMapper.class);
        processInstanceMapper = ConnectionFactory.getSqlSession().getMapper(ProcessInstanceMapper.class);
        taskInstanceMapper = ConnectionFactory.getSqlSession().getMapper(TaskInstanceMapper.class);
        alertManager = new AlertManager();
    }

    /**
     * send worker alert fault tolerance
     */
    @Test
    public void sendWarnningWorkerleranceFaultTest(){
        // process instance
        ProcessInstance processInstance = processInstanceMapper.queryDetailById(13028);

        // set process definition
        ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(47);
        processInstance.setProcessDefinition(processDefinition);


        // fault task instance
        TaskInstance toleranceTask1 = taskInstanceMapper.queryById(5038);
        TaskInstance toleranceTask2 = taskInstanceMapper.queryById(5039);

        List<TaskInstance> toleranceTaskList = new ArrayList<>(2);
        toleranceTaskList.add(toleranceTask1);
        toleranceTaskList.add(toleranceTask2);

B
baoliang 已提交
79
        alertManager.sendAlertWorkerToleranceFault(processInstance, toleranceTaskList);
L
ligang 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    }


    /**
     * send worker alert fault tolerance
     */
    @Test
    public void sendWarnningOfProcessInstanceTest(){
        // process instance
        ProcessInstance processInstance = processInstanceMapper.queryDetailById(13028);

        // set process definition
        ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(47);
        processInstance.setProcessDefinition(processDefinition);


        // fault task instance
        TaskInstance toleranceTask1 = taskInstanceMapper.queryById(5038);
        toleranceTask1.setState(ExecutionStatus.FAILURE);
        TaskInstance toleranceTask2 = taskInstanceMapper.queryById(5039);
        toleranceTask2.setState(ExecutionStatus.FAILURE);

        List<TaskInstance> toleranceTaskList = new ArrayList<>(2);
        toleranceTaskList.add(toleranceTask1);
        toleranceTaskList.add(toleranceTask2);

B
baoliang 已提交
106
        alertManager.sendAlertProcessInstance(processInstance, toleranceTaskList);
L
ligang 已提交
107 108 109
    }

}