package com.elab.log.ext;


import com.elab.core.async.consumer.TaskConsumer;
import com.elab.core.async.pruducer.TaskProducer;
import com.elab.core.async.store.TaskExecutorQueue;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class CatTaskProducerTest {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private TaskProducer producer;

    @Before
    public void init() {
        TaskExecutorQueue queue = new TaskExecutorQueue(50);
        TaskConsumer taskConsumer = new TaskConsumer(queue);
        taskConsumer.startRealTimeConsumer();
        taskConsumer.startSchedulingConsumer(5);
        producer = new CatTaskProducer(queue);
    }

    @Test
    public void sendRealTimeQueue() throws IOException {
        for (int i = 0; i < 11; i++) {
            int finalI = i;
            System.out.println("==业务执行开始==" + i);
            producer.sendRealTimeQueue(() -> {
                System.out.println("-------操作异步开始----------" + finalI);
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("-----异步操作结束-----------" + finalI);
            });
            System.out.println("==业务执行完成==" + i);
        }
        System.in.read();
    }

    public void sendRealTimeQueue1() {
    }
}
