// Path: druid-spring-boot/druid-spring-boot-autoconfigure/src/main/java/com/github/trang/druid/autoconfigure/datasource/DruidDataSource2.java
// public class DruidDataSource2 extends AbstractDruidDataSource2 {
// 
//     private static final long serialVersionUID = 4980333179163868927L;
// 
// }
// 
// Path: druid-spring-boot-example/druid-spring-boot-mybatis-example/src/main/java/com/github/trang/druid/example/mybatis/config/DynamicDataSource.java
// @Slf4j
// @Getter
// @RequiredArgsConstructor
// public class DynamicDataSource extends AbstractRoutingDataSource {
// 
//     private final AtomicInteger count = new AtomicInteger();
//     private final Map<String, DataSource> targetDataSources;
// 
//     /**
//      * 基于轮询算法指定实际的数据源
//      *
//      * @return dataSource
//      */
//     @Override
//     protected Object determineCurrentLookupKey() {
//         int i = count.incrementAndGet();
//         List<String> list = new ArrayList<>(targetDataSources.keySet());
//         String dataSource = list.get(i % list.size());
//         log.info(">>>>>> 当前数据库: {} <<<<<<", dataSource);
//         return dataSource;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
//         super.setTargetDataSources(new HashMap<>(targetDataSources));
//         super.afterPropertiesSet();
//     }
// 
// }


import static org.junit.Assert.assertEquals;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import com.alibaba.druid.pool.DruidDataSource;
import com.github.trang.druid.autoconfigure.datasource.DruidDataSource2;
import com.github.trang.druid.example.mybatis.config.DynamicDataSource;
    public void testDynamicDataSource() {
        assertEquals(dataSource.getTargetDataSources().size(), 2);
    }


    @Autowired(required = false)
    private Map<String, DruidDataSource> dataSourceMap;
    @Autowired(required = false)
    private Map<String, DruidDataSource> druidDataSourceMap;
    @Autowired(required = false)
    private Map<String, DruidDataSource> foolDataSourceMap;
    @Autowired(required = false)
    private List<DruidDataSource> dataSourceList;
    @Autowired(required = false)
    private List<DruidDataSource> dataSources;
    @Autowired(required = false)
    private List<DruidDataSource> druidDataSourceList;
    @Autowired(required = false)
    private List<DruidDataSource> druidDataSources;
    @Autowired(required = false)
    private List<DruidDataSource> foolDataSources;
    @Autowired(required = false)
    private Collection<DruidDataSource> druidDataSourceCollection;
    @Autowired(required = false)
    private Set<DruidDataSource> druidDataSourceSet;
    @Autowired(required = false)
    private DruidDataSource[] druidDataSourceArray;


    @Autowired(required = false)
// Path: druid-spring-boot/druid-spring-boot-autoconfigure/src/main/java/com/github/trang/druid/autoconfigure/datasource/DruidDataSource2.java
// public class DruidDataSource2 extends AbstractDruidDataSource2 {
// 
//     private static final long serialVersionUID = 4980333179163868927L;
// 
// }
// 
// Path: druid-spring-boot-example/druid-spring-boot-mybatis-example/src/main/java/com/github/trang/druid/example/mybatis/config/DynamicDataSource.java
// @Slf4j
// @Getter
// @RequiredArgsConstructor
// public class DynamicDataSource extends AbstractRoutingDataSource {
// 
//     private final AtomicInteger count = new AtomicInteger();
//     private final Map<String, DataSource> targetDataSources;
// 
//     /**
//      * 基于轮询算法指定实际的数据源
//      *
//      * @return dataSource
//      */
//     @Override
//     protected Object determineCurrentLookupKey() {
//         int i = count.incrementAndGet();
//         List<String> list = new ArrayList<>(targetDataSources.keySet());
//         String dataSource = list.get(i % list.size());
//         log.info(">>>>>> 当前数据库: {} <<<<<<", dataSource);
//         return dataSource;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
//         super.setTargetDataSources(new HashMap<>(targetDataSources));
//         super.afterPropertiesSet();
//     }
// 
// }


// Path: druid-spring-boot-example/druid-spring-boot-mybatis-example/src/test/java/com/github/trang/druid/example/mybatis/test/coveralls/DynamicDataSourceTests.java
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import com.alibaba.druid.pool.DruidDataSource;
import com.github.trang.druid.autoconfigure.datasource.DruidDataSource2;
import com.github.trang.druid.example.mybatis.config.DynamicDataSource;

    public void testDynamicDataSource() {
        assertEquals(dataSource.getTargetDataSources().size(), 2);
    }


    @Autowired(required = false)
    private Map<String, DruidDataSource> dataSourceMap;
    @Autowired(required = false)
    private Map<String, DruidDataSource> druidDataSourceMap;
    @Autowired(required = false)
    private Map<String, DruidDataSource> foolDataSourceMap;
    @Autowired(required = false)
    private List<DruidDataSource> dataSourceList;
    @Autowired(required = false)
    private List<DruidDataSource> dataSources;
    @Autowired(required = false)
    private List<DruidDataSource> druidDataSourceList;
    @Autowired(required = false)
    private List<DruidDataSource> druidDataSources;
    @Autowired(required = false)
    private List<DruidDataSource> foolDataSources;
    @Autowired(required = false)
    private Collection<DruidDataSource> druidDataSourceCollection;
    @Autowired(required = false)
    private Set<DruidDataSource> druidDataSourceSet;
    @Autowired(required = false)
    private DruidDataSource[] druidDataSourceArray;


    @Autowired(required = false)
    private Map<String, DruidDataSource2> dataSource2Map;