package cd.casic.server;

import cd.casic.ci.process.engine.manager.RunContextManager;
import cd.casic.ci.process.engine.message.TaskRunMessage;
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
import cd.casic.ci.process.engine.runContext.SecondStageRunContext;
import cd.casic.ci.process.engine.runContext.TaskRunContext;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.ci.process.process.dataObject.stage.PipStage;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.framework.mq.redis.core.RedisMQTemplate;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class RedisMqTest {
    @Resource
    RedisMQTemplate redisMQTemplate;
    @Resource
    RunContextManager contextManager;
    @Test
    public void test01(){
        System.out.println("h w !");
        redisMQTemplate.send(new TaskRunMessage());
    }

    @Test
    public void test02(){
        System.out.println("h w !");
        TaskRunMessage taskRunMessage = new TaskRunMessage();
        PipTask pipTask = new PipTask();
        pipTask.setTaskType("testTask");
        pipTask.setId("testTaskId");
        pipTask.setStageId("testStage");
        PipPipeline pipeline = new PipPipeline();
        pipeline.setId("testPipeline");
        PipelineRunContext pipelineRunContext = new PipelineRunContext(pipeline,1);
        PipStage stage = new PipStage();
        stage.setId("testStage");
        stage.setParentId("testPipeline");
        SecondStageRunContext secondStageRunContext = new SecondStageRunContext(stage,1,pipelineRunContext,new ConcurrentHashMap<>());
        TaskRunContext taskRunContext = new TaskRunContext(pipTask,secondStageRunContext,new HashMap<>());
        contextManager.contextRegister(pipelineRunContext);
        contextManager.contextRegister(secondStageRunContext);
        contextManager.contextRegister(taskRunContext);
        taskRunMessage.setTask(pipTask);
        redisMQTemplate.send(taskRunMessage);
        try {
            Thread.sleep(5000L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
