package com.elab.redis.componts.config;

import com.elab.redis.RedissonApplication;
import com.elab.redis.componts.config.scope.RedisConfigRefreshCallback;
import com.elab.redis.componts.config.scope.RedisConfigRefreshHelper;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ConfigController.class, RedisRefreshConfigure.class, RedissonApplication.class})
//@EnableElabRedis
public class ConfigCenterRedisStaterTest extends TestCase {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ConfigController configController;

    @Autowired
    RedisConfigRefreshCallback refreshConfig;

    @Test
    public void test() throws Exception {
        while (true) {
            // 通过redis 操作 publish test-redis-* xxx
            // xxx 代表任意字符,主要目的是为了触发监听回调
            String config = configController.config();
            logger.info("加载完成。。" + config);

            String username = RedisConfigRefreshHelper.getInstance().get("username");
            System.out.println("username : " + username);
            Thread.sleep(5000);
        }
    }

}