package com.elab.spring.utils;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Transaction;
import com.elab.spring.config.ThreadConfiguration;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/11/18 16:16
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ThreadConfiguration.class)
public class ThreadProcessUtilsTest extends TestCase {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Test
    public void testAddRealTimeQueue() throws Exception {
        Transaction transaction = Cat.newTransaction("test", "msg");
        logger.info("这时候开始处理 : " + Cat.getCurrentMessageId());
        System.out.println("LOG : " + Cat.getCurrentMessageId());
        ThreadProcessUtils.addRealTimeQueue(() -> {
            logger.info("这是一个异步消息" + Cat.getCurrentMessageId());
        }, null);
        logger.info("处理完成了");
        transaction.setSuccessStatus();
        transaction.complete();
        System.in.read();
    }

    @Test
    public void testAddSchedulingList() throws Exception {
        logger.info("sadfasdfsdfsad:::" + Cat.getCurrentMessageId());
        ThreadProcessUtils.addSchedulingList(()->{
            System.out.println("这是一个调度操作" + Cat.getCurrentMessageId());
        });
        System.in.read();
    }

}