package com.jay.monitor.data.server.factory;

import com.jay.monitor.data.server.config.props.MonitorProperties;
import com.jay.monitor.data.server.enums.DataSplitType;
import com.jay.monitor.data.server.factory.callback.DefaultIdChangeCallback;
import com.jay.monitor.data.server.factory.generate.DayIdGenerate;
import com.jay.monitor.data.server.store.SplitDataManager;
import com.jay.monitor.data.server.store.mysql.MysqlDDLProcess;
import com.jay.monitor.data.server.utils.ThreadUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/11/9 10:59
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MonitorProperties.class, DataSourceAutoConfiguration.class, MysqlDDLProcess.class, SplitDataManager.class, DayIdGenerate.class, DataIdFactory.class, DefaultIdChangeCallback.class})
public class DataIdFactoryTest {

    @Autowired
    private DataIdFactory dataIdFactory;

    @Autowired
    private DayIdGenerate dayIdGenerate;

    @Test
    public void getCurrentId() throws Exception {
        ThreadUtils.concurrent(5, 10, 2000, () -> {
            dayIdGenerate.setM_timestamp(11L);
            dayIdGenerate.setDefaultId("201106");
            String currentId = dataIdFactory.getCurrentId(DataSplitType.DAY);
            return currentId;
        });
        System.in.read();
    }
}