package io.shardingsphere.core.metadata.datasource;

import com.google.common.collect.Lists;
import io.shardingsphere.core.api.config.ShardingRuleConfiguration;
import io.shardingsphere.core.api.config.TableRuleConfiguration;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.rule.ShardingRule;
import org.junit.Before;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;

public class ShardingDataSourceMetaDataTest {
    
    private ShardingDataSourceMetaData actual;
    
    @Before
    public void setUp() {
        TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
        tableRuleConfig.setLogicTable("t_order");
        tableRuleConfig.setActualDataNodes("ds_${0..1}.t_order_${0..1}");
        ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
        ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds_0", "ds_1"));
        Map<String, String> dataSourceURLs = new LinkedHashMap<String, String>() {{ put("ds_0", "jdbc:mysql://127.0.0.1:3306/db_0"); put("ds_1", "jdbc:mysql://127.0.0.1:3306/db_1");}};
        actual = new ShardingDataSourceMetaData(dataSourceURLs, shardingRule, DatabaseType.MySQL);
    }
    
    @Test
    public void testGetAllInstanceDataSourceNames() {
        assertEquals(actual.getAllInstanceDataSourceNames(), Lists.newArrayList("ds_0"));
    }
    
    @Test
    public void testGetActualSchemaName() {
        assertEquals(actual.getActualSchemaName("ds_0"), "db_0");
    }
}
@@ -86,16 +86,87 @@
 .Lists;%0A
+import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration;%0A
 import i
@@ -441,16 +441,41 @@
 .Test;%0A%0A
+import java.util.Arrays;%0A
 import j
@@ -885,17 +885,21 @@
 es(%22
-ds
+master
 _$%7B0..
-1
+2
 %7D.t_
@@ -995,32 +995,160 @@
 onfiguration();%0A
+        MasterSlaveRuleConfiguration msConfig = new MasterSlaveRuleConfiguration(%22ms_0%22, %22master_0%22, Arrays.asList(%22slave_0%22));%0A
         sharding
@@ -1202,16 +1202,86 @@
 onfig);%0A
+        shardingRuleConfig.getMasterSlaveRuleConfigs().add(msConfig);%0A
         
@@ -1369,20 +1369,73 @@
 st(%22
-ds_0%22, %22ds_1
+master_0%22, %22master_1%22, %22master_2%22, %22slave_0%22, %22slave_1%22, %22slave_2
 %22));
@@ -1524,18 +1524,22 @@
 %7B%7B put(%22
-ds
+master
 _0%22, %22jd
@@ -1568,23 +1568,39 @@
 306/
-db_0%22); put(%22ds
+master_0%22);%0A        put(%22master
 _1%22,
@@ -1633,12 +1633,128 @@
 306/
-db_1
+master_1%22); put(%22master_2%22, %22jdbc:mysql://127.0.0.1:3307/master_2%22); put(%22slave_0%22, %22jdbc:mysql://127.0.0.2:3306/slave_0
 %22);%7D
@@ -2011,20 +2011,36 @@
 ayList(%22
-ds_0
+master_0%22, %22master_2
 %22));%0A   
@@ -2154,19 +2154,27 @@
 me(%22
-ds
+master
 _0%22), %22
-db
+master
 _0%22)

add slave datasources